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
Create ➜tar -tvf myarchive.tar
List contents ➜tar -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 archive ➜tar -tzvf myarchive.tar.gz
List contents ➜tar -xzvf myarchive.tar.gz
Extract
or compressed with bzip2
:
➜tar -cjvf myarchive.tar.bz2 mydir
Create archive ➜tar -tjvf myarchive.tar.bz2
List contents ➜tar -xjvf myarchive.tar.bz2
Extract
or compressed with compress
:
➜tar -cZvf myarchive.tar.Z mydir
Create archive ➜tar -tZvf myarchive.tar.Z
List contents ➜tar -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
| 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.