Name

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

Synopsis

tar [options] [files]

The tar program packs multiple files and directories into a single archive file for transport. Originally for backing up files onto a tape drive (its name is short for “tape archive”), tar is still a common file-packaging format. Using various options, you can create archive files, list their contents, and extract the files:

tar -cvf myarchive.tar mydir      Createtar -tvf myarchive.tar            List contentstar -xvf myarchive.tar            Extract

It’s your responsibility to name the archive file properly; tar will not add a .tar suffix for you. TAR files are usually compressed with the other programs we covered in this section. Here are sample commands for archiving a directory mydir when compressed with gzip:

tar -czvf myarchive.tar.gz mydir      Create archivetar -tzvf myarchive.tar.gz            List contentstar -xzvf myarchive.tar.gz            Extract

or compressed with bzip2:

tar -cjvf myarchive.tar.bz2 mydir     Create archivetar -tjvf myarchive.tar.bz2           List contentstar -xjvf myarchive.tar.bz2           Extract

or compressed with compress:

tar -cZvf myarchive.tar.Z mydir      Create archivetar -tZvf myarchive.tar.Z            List contentstar -xZvf myarchive.tar.Z            Extract

If you specify files on the command line, only those files are processed. To extract file1, file2, and file3 from a TAR file myarchive.tar, run:

tar -xvf myarchive.tar file1 file2 file3

Otherwise, the entire archive is processed.

Useful options

-c

Create an archive. You’ll have ...

Get Macintosh Terminal 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.