Article 19.5, discussed creating and unpacking compressed tar archives with , and tar. This article explains how to simplify those two-step processes. The first command line below creates a gzipped archive; the second extracts it:
tar cf -
| gzip > archive.tar.gz%
gzcat archive.tar.gz | tar xf -
gzcat uncompresses a file (the gzip format, as
well as older compress and pack formats), sending the result to
standard output. With the f option, and
listed as a filename, tar writes to standard output when
creating an archive and reads from standard input when extracting.
You don't need to create the larger, uncompressed file; you can
store the archive permanently in its compressed form.
To extract only some of the files in the archive, give the
pathnames on the command line exactly as they're stored in
Otherwise, tar will extract all the files.
(For a list of the exact pathnames, use
tar tf -.)
GNU tar makes this even easier. As article 19.6 shows, the GNU z option creates or extracts a gzipped archive directly. Here are the two examples above using the z option:
tar czf archive.tar.gz
tar xzf archive.tar.gz
Instead of |
NOTE: If you extract files from an archive that you didn't create, the files you extract may not belong to you. Here's why. On many non-BSD systems, when tar extracts a file, the file will be owned by the same On systems with that problem, you can add the o option (for example,that owned the file when the archive was created. If that UID isn't yours, tar may extract directories you can't modify and files you can't edit.
xof) to be sure that files extracted will belong to you.