In Unix, what is tar, and how do I use it?
In Unix, the name of the
tar command is
short for tape archiving, the storing of entire file systems onto
magnetic tape, which is one use for the command. However, a more
common use for
tar is to simply combine a few files into
a single file, for easy storage and distribution.
To combine multiple files and/or directories into a single file, use the following command:
tar -cvf file.tar inputfile1 inputfile2
the files and/or directories you want to combine. You can use any
name in place of
file.tar, though you should keep the
.tar extension. If you don't use the
tar assumes you really
do want to create a tape archive instead of joining
up a number of files. The
v option tells
tar to be verbose, which reports all files as they are
To separate an archive created by
tar into separate
files, at the shell prompt, enter:
tar -xvf file.tar
Compressing and uncompressing tar files
Many modern Unix systems, such as Linux, use
tar, a version of
produced by the Free Software Foundation. If your system
tar, you can easily use
GNU file compression program) in conjunction with
create compressed archives. To do this, enter:
tar -cvzf file.tar.gz inputfile1 inputfile2
z option tells
to zip the archive as it is created. To unzip such a zipped tar file,
tar -xvzf file.tar.gz
Alternatively, if your system does not use GNU
tar, but nonetheless does have
gzip, you can
still create a compressed tar file, via the following command:
tar -cvf - inputfile1 inputfile2 | gzip > file.tar.gz
gzip isn't available on your
system, use the Unix
compress command instead. In the
example above, replace
and change the
.gz extension to
compress command specifically looks for an uppercase
Z). You can use other compression programs in this way as well. Just
be sure to use the appropriate extension for the compressed file, so
you can identify which program to use to decompress the file
If you are not using GNU
tar, to separate a tar
archive that was compressed by
gunzip -c file.tar.gz | tar -xvf -
Similarly, to separate a tar archive compressed with the Unix
compress command, replace
Lastly, the extensions
are equivalent; they both signify a tar file zipped with
Keep the following in mind when using the
- The order of the options sometimes matters. Some versions of
tarrequire that the
foption be immediately followed by a space and the name of the
.tarfile being created or extracted.
- Some versions require a single dash before the option string
tar does not have either of these limitations.
tar command has many additional command options
available. For more information, consult the manual
page. At the shell prompt, enter:
tar comes with additional documentation, including
a tutorial, accessible through the GNU Info interface. You can access
this documentation by entering:
Within the Info interface, press
question mark) for a list of commands.
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.
This is document acfi in the Knowledge Base.
Last modified on 2013-05-29.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.