Unarchiving Files with tar


Unarchiving Files with tar

You'll also use tar to unarchive files, where you take all of the individual files out of the single tarred filelike dumping the bunch of toys out of the toy boxas shown in Code Listing 13.6.

Code Listing 13.6. Untarring files reconstructs the original directory structure.

[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]$ 

To Unarchive Files with tar:

  • 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.

To Unarchive Selected Files with tar:

  • 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).

Code Listing 13.7. Unarchive just a single file to replace a missing or corrupt file.

[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.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net