How to Create an Archive using tar Command

Share this Article :

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)
Options Description
A, –catenate, –concatenate Append tar files to an archive.
c, –create Create a new archive.
d, –diff, –compare Calculate any differences between the archive and the file system.
–delete Delete from the archive. (This function doesn’t work on magnetic tapes).
r, –append Append files to the end of a tar archive.
t, –list List the contents of an archive.
–test-label Test the archive label, and exit.
u, –update Append files, but only those that are newer than the copy in the archive.
x, –extract, –get Extract files from an archive.
-v, –verbose Operate verbosely.
-z, –gzip, –gunzip This 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, –uncompress tar will use the compress program when operating on files.
Also Read :   How to Install Nginx With PHP5 (and PHP-FPM) and MySQL (LEMP) On Ubuntu 14.04

How to archive /home/scriptsmy directory :

[[email protected] ~]# tar -cvf scriptsmy-07-11-2014.tar /home/scriptsmy

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

[[email protected] ~]# tar cvzf scriptsmy-07-11-2014.tar.gz /home/scriptsmy

Leave a Reply