O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

tar — stdin  stdout  - file  -- opt  --help  --version

Synopsis

tar [options] [files]

The tar program was originally for backing up files onto a tape drive (its name is short for “tape archive”). Although tape has lost its popularity, tar is still the most common file-packaging format for Linux. It can pack multiple files and directories into a single file for transport, optionally compressed.

$ tar -czvf myarchive.tar.gz mydir      Create
$ tar -tzvf myarchive.tar.gz            List contents
$ tar -xzvf myarchive.tar.gz            Extract

If you actually have a tape drive, simply specify the drive’s device (such as /dev/tape) as the destination file:

$ tar -cf /dev/tape myfile1 myfile2

If you specify files on the command line, only those files are processed:

$ tar -xvf myarchive.tar file1 file2 file3

Otherwise, the entire archive is processed.

Useful options

-c

Create an archive. You’ll have to list the input files and directories on the command line.

-r

Append files to an existing archive.

-u

Append new/changed files to an existing archive.

-A

Append one archive to the end of another: e.g., tar -A -f first.tar second.tar appends the contents of second.tar to first.tar. Does not work for compressed archives.

-t

List the archive.

-x

Extract files from the archive.

-f file

Read the archive from, or write the archive to, the given file. This is usually a tar file on disk (such as myarchive.tar) but can also be a tape drive (such as /dev/tape).

-d

Diff (compare) the archive against the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required