Name

tar [options] [files] — tar

Synopsis

/bin stdin stdout - file -- opt --help --version

The tar (tape archive) program does more than read and write files to and from a tape drive:

$ tar -cf /dev/tape myfile1 myfile2

it also lets you create and extract from tar files, which are a standard means of packaging files on Linux and Unix systems:

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

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

$ tar -xvf /dev/tape 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 (e.g., a tar file) to the end of another archive: e.g., tar -A -f /dev/tape myfile.tar.

-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 could be a device (such as /dev/tape) or a plain file if you want to create a traditional Linux tar file.

-d

Diff (compare) the archive against the filesystem.

-z

Compress (while writing) or uncompress (while reading) the data with gzip.

-j

Compress (while writing) or uncompress (while reading) the data with bzip2.

-Z

Compress (while writing) or uncompress (while reading) the data with Unix compress.

-b N

Use a block size of N * 512 bytes.

-v

Verbose mode: print extra ...

Get Linux Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.