Creating tar Archives



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

Creating tar Archives

The -c option to the tar command creates an archive. In this example we use the option -f /dev/rmt0 to write the archive to the tape drive. The archive contains all the files and directories below the present working directory (nc in this example):

%tar -cvf file.tar *   	   Create archive of all directories into file file.tar.    
%tar -cvf /dev/rmt0 nc   	   Create archive of nc on device rmt0.   
%tar -cv -f /dev/rmt0 nc   	   Alternative form for above.   
a nc/About, 3320 bytes, 7 tape blocks.   	   The ``a''  is for ``add.''   
a nc/doc/mknewsrc.1, 3106 bytes, 7 tape blocks.   	   
a nc/doc/ncc.1, 6503 bytes, 13 tape blocks.   	   
a nc/doc/append.mm, 91031 bytes, 178 tape blocks.   	   
a nc/Makefile, 1464 bytes, 3 tape blocks.   	   
a nc/READ.ME, 2626 bytes, 6 tape blocks.   	   
a nc/License, 4082 bytes, 8 tape blocks.   	   

Note that the path names of the files in the archive begin at the directory nc specified on the command line. This means at the time the archive is untarred, the directory nc will be created in the current user's directory and all archived files will be placed in it. In contrast, if we had stated the full path name of the nc directory, the files in the archive would have an absolute path name, for example,

%tar -cvf /dev/rmt0 /usr/src/nc   	Full path name.   
a /usr/src/nc/About, 3320 bytes, 7 tape blocks.   	   
a /usr/src/nc/doc/mknewsrc.1, 3106 bytes, 7 tape blocks.   	   
a /usr/src/nc/doc/ncc.1, 6503 bytes, 13 tape blocks.   	   
a /usr/src/nc/doc/append.mm, 91031 bytes, 178 tape blocks.   	   
a /usr/src/nc/Makefile, 1464 bytes, 3 tape blocks.   	   
a /usr/src/nc/READ.ME, 2626 bytes, 6 tape blocks.   	   
a /usr/src/nc/License, 4082 bytes, 8 tape blocks.   	   

Now with the full path name specified, the untarred files will be placed in that directory regardless of the current one.

You may create an archive containing more than one directory by just listing the additional files or directories on the command line as well:

%tar -cvf /dev/rmt0 weather asroot   	Create archive.   
a weather/README 9 blocks.   	   
a weather/how2ftp 5 blocks.   	   
a weather/pricing 7 blocks.   	   
a weather/catds 101 blocks.   	   
a weather/datav.1 15 blocks.   	   
a asroot/str.c 2 blocks.   	   
a asroot/Makefile 1 blocks.   	   
a asroot/asroot.c 8 blocks.   	   
a asroot/asrbsd.c 8 blocks.   	   
a asroot/asr.c 8 blocks.   	   

As we have said before, multi-diskette tars should be avoided if you wish to read the tar on a different system. Some systems allow multi-diskette or multi-volume tar archives, but many do not. To prevent your tar from spilling over onto a second medium, include a smaller number of files on the tar command, and use several tar's.



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