Manages tar archives
A tar archive is a file collection represented by a single "tar" file. They're
used for backups and distributing collections of files. The files comprising a
software package are often offered for download as tar
archives.
Note: In all of the following examples the tar archive being created will be overwritten if it already exists.
tar -cvf file.tar dir/
- Create a tar archive calledfile.tar
that contains the contents of directorydir/
.tar -cvf ~/pictures.tar ~/Photos/*.png
- Create a tar archive calledpictures.tar
in the user's home directory containing the .png files in the their~/Photos
directory.tar -cjvf file.tar.bz2 dir/
- Creates a tar archive calledfile.tar.bz2
which containsdir/
and is compressed withbzip2
.tar -czvf file.tar.gz dir/
- Creates a tar archive calledfile.tar.gz
which containsdir/
and is compressed withgzip
.
tar -xzvf file.tar.gz
- Extract the contents of gzipped tar archivefile.tar.gz
into the current directory. In this example the tar archive has been compressed withgzip
, so we use the-z
switch to indicate that it should be uncompressed withgzip
before extracting its contents.tar -xjvf file.tar.bz2
- As above, but this time the archive has been compressed withbzip2
, so the-j
switch is used to uncompress it.
tar -tvf file.tar
- Lists the files and directories contained withinfile.tar
.tar -tzvf file.tar.gz
- Lists the files and directories contained within the gzip'dfile.tar.gz
.
Note: tar
cannot update compressed archives, so in this case you'll need to
extract the archive, add the new files to the same directory, then create a
new archive.
tar -rvf file.tar file2
- Appendsfile2
to the tar archivefile.tar
, i.e. add a new file to an existing archive.