previous contents up next

Unix for Advanced Users

6. Manipulating Files

6.6. How do I unpack this file?

6.6.2. Archive files

Many files and entire directory trees can be archived into a single file for backup, long-term storage or for distributing groups of files by e-mail or over the worldwide web. Archive files are often compressed.

6.6.2.1. File names ending with .tar, .tgz, and .taz: tar

Tape archive files, tar files, are the most common method of distributing files in the Unix world. They are commonly used to backup files and directory trees.

To extract files from an uncompressed archive (.tar file), use tar -xf tarfile. File names will be listed as files are extracted if you use the -v flag.

To list the contents of a tar file without extracting files, use tar -tf tarfile.

Files can be extracted from compressed archives (.tgz, .tar.gz, and .taz files) by two methods. You can uncompress the archive (see Compressed files), and then untar the archive, or you can pipe uncompressed file contents directly to tar. For example, gunzip -c mucho.tar.gz | tar -xf - uncompresses mucho.tar.gz and pipes the contents to tar for extraction.

6.6.2.2. File names ending with .cpio: cpio

To extract files from a cpio archive, pass the archive to cpio as its standard input. For example, cpio -id < cpiofile. The -i flag indicates that cpio is reading in the archive to extract files, and the -d flag tells cpio to construct directories as necessary. You can also use the -v flag to have file names listed as files are extracted.

To list the contents of cpio archives use the -i and -t flags.

A natural way to process compressed cpio files is to uncompress them, piping the results to cpio. Example: uncompress -c mucho.cpio.Z | cpio -ivd.

previous contents up next