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)
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.
READ  How to Install the Dependencies for GForge Community Edition and GForge Advanced Server

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 *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>