Reading tar Archives



next up previous contents index
Next: Using Tape Drives Up: The tar Command Previous: Listing tar Archives

Reading tar Archives

Once you have files archived onto some medium, it is all too easy to write over them. Better to be safe and spend the money on extra media than to waste hours or days of your time. To read a tar archive, first lock your tape or diskette into read-only. An error of one letter could erase your data if you don't follow this precaution. On cartridge tapes this means rotating the little cylinder to the closed position; for 8-mm tapes this means sliding the cover in back to close the notch; and on diskettes, this means slipping the tab to open the notch (nice that the procedure is standardized).   

To extract all the files in an archive, use the -x option instead of the -t option:

%tar -xvf /dev/fd0   	Extract all files and directories.   
x weather/README, 4313 bytes, 9 tape blocks.   	   
x weather/how2ftp, 2185 bytes, 5 tape blocks.   	   
x weather/pricing, 3351 bytes, 7 tape blocks.   	   
x weather/catds, 51239 bytes, 101 tape blocks.   	   
x weather/datav.1, 7647 bytes, 15 tape blocks.   	   

To extract all files and subdirectories in one directory:

%tar -xvf file.tar newsclip    	Extract all files from a tar file's directory.   
x newsclip/About, 3320 bytes, 7 tape blocks.   	   
x newsclip/doc/mknewsrc.1, 3106 bytes, 7 tape blocks.   	   
x newsclip/doc/ncc.1, 6503 bytes, 13 tape blocks.   	   
x newsclip/doc/append.mm, 91031 bytes, 178 tape blocks.   	   
x newsclip/Makefile, 1464 bytes, 3 tape blocks.   	   
x newsclip/READ.ME, 2626 bytes, 6 tape blocks.   	   
x newsclip/License, 4082 bytes, 8 tape blocks.   	   

In both these cases, the files and directories will be placed in the current working directory of the user since the archives were created without the full path name of the files. If they had been created with the full path names, as in one example above, the files and directories would be copied only in the same location from which they came-regardless of the directory the user is in when the tar command is issued.

To extract a specific directory and all subdirectories below it or specific files from an archive, list the full name of the file or directory on the command line:

%tar -xvf file.tar newsclip/READ.ME newsclip/License   	   
x newsclip/READ.ME, 2626 bytes, 6 tape blocks.   	   
x newsclip/License, 4082 bytes, 8 tape blocks.   	   
%   	   

Note that the name must appear exactly as it does in the archive; if you are not sure of the name, use the -t option to get the names first.



next up previous contents index
Next: Using Tape Drives Up: The tar Command Previous: Listing tar Archives