How to Create an Archive using tar Command

In Linux, tar command is the primary utility to create compressed archive files and directories. “tar” stands for tape archive and it is actually archiving file format. The following example will show you how to creating an archive using tar command.

tar option(s) archive_name file_name(s)
OptionsDescription
A, –catenate, –concatenateAppend tar files to an archive.
c, –createCreate a new archive.
d, –diff, –compareCalculate any differences between the archive and the file system.
–deleteDelete from the archive. (This function doesn’t work on magnetic tapes).
r, –appendAppend files to the end of a tar archive.
t, –listList the contents of an archive.
–test-labelTest the archive label, and exit.
u, –updateAppend files, but only those that are newer than the copy in the archive.
x, –extract, –getExtract files from an archive.
-v, –verboseOperate verbosely.
-z, –gzip, –gunzipThis option tells tar to read or write archives through gzip, allowing tar to directly operate on several kinds of compressed archives transparently. This option should be used, for example, when operating on files with the extension.tar.gz.
-Z, –compress, –uncompresstar will use the compress program when operating on files.
READ  How to Find Big Files Size on Linux RHEL/CentOS

How to archive /home/scriptsmy directory :

[root@vps ~]# tar -cvf scriptsmy-07-11-2014.tar /home/scriptsmy

How to archive /home/scriptsmy directory then gunzip it :

[root@vps ~]# tar cvzf scriptsmy-07-11-2014.tar.gz /home/scriptsmy

Leave a Reply

Your email address will not be published. Required fields are marked *