You’ll also use tar to unarchive files, where you take all of the individual files out of the single tarred file—like dumping the bunch of toys out of the toy box—as shown in Code Listing 13.6.
[ejr@hobbes compression]$ tar -xf → labrea.tar [ejr@hobbes compression]$ ls -l Labrea/ total 483 -rw-r-r-1 ejr users 53678 Jul 27 → 10:05 bigfile.gz -rw-r-r-1 ejr users 128886 Jul 27 → 10:06 mammoth.jpg -rw-r-r-1 ejr users 177607 Jul 27 → 10:05 house.uue -rw-r-r-1 ejr users 128886 Jul 27 → 10:06 rowboat.jpg [ejr@hobbes compression]$ |
tar -xf labrea.tar
At the shell prompt, type tar -xf (here, x means extract) followed by the name of the tarred file you want to unarchive. The bunch of once-tarred files will be separated into the original files or directories, as shown in Code Listing 13.6.
tar -xf labrea.tar "*mammoth*"
You can also extract only specified files from a tar file. You might do this to restore just a couple of files from a backup archive, for example. This command extracts all files that have mammoth in their names from the labrea.tar file and places them back where they belong (Code Listing 13.7).
[ejr@hobbes compression]$ tar -xf → labrea.tar "*mammoth*" [ejr@hobbes compression]$ ls -l Labrea/m* -rw-r-r-1 ejr users 128886 Jul 27 → 10:06 Labrea/mammoth.jpg [ejr@hobbes compression]$ |
✓ Tips
Consider moving tarred files into a temporary directory before you unarchive them. When you unarchive, tar overwrites any files with the same names as files that are extracted. Using a temporary directory will prevent this.
Use tar -tf filename to list the files (to check your work, perhaps, or find a backup file) without actually unarchiving the files.