tar archives and extracts multiple files onto a single tar, file archive, called a tarfile. A tarfile is usually a magnetic tape, but it can be any file. tar's actions are controlled by the first argument, the key, a string of characters containing exactly one function letter from the set crtux, and one or more of the optional function modifiers listed below. Other arguments to tar are file or directory names that specify which files to archive or extract. In all cases, the appearance of a directory name refers recursively to the files and subdirectories of that directory.
example% cd fromdir; tar cf - . | (cd todir; tar xfBp -)
filename/: cannot create
when they encounter it.
If a file name is preceded by -I then the filename is opened. A list filenames, one per line, is treated as if each appeared separately on the command line. Be careful of trailing white space in both include and exclude file lists.
In the case where excluded files (see
X
option)
also exist, excluded files take
precedence over all included files.
So, if a file is specified in both the
include and exclude files (or on the command line),
it will be excluded.
If a file name is preceded by -C in a c (create) or r (replace) operation, tar will perform a chdir (see csh.1 to that file name. This allows multiple directories not related by a close common parent to be archived using short relative path names. See EXAMPLES below.
Note: the
-C
option only applies to
one
following directory name and
one
following file name.
To archive files from /usr/include and from /etc, one might use:
example% tar c -C /usr include -C /etc .
If you get a table of contents from the resulting tarfile, you will see something like:
include/ include/a.out.h and all the other files in /usr/include ... /chown and all the other files in /etc
Here is a simple example using tar to create an archive of your home directory on a tape mounted on drive /dev/rmt0:
example% cd example% tar cvf /dev/rmt0 . messages from tar
The c option means create the archive; the v option makes tar tell you what it is doing as it works; the f option means that you are specifically naming the file onto which the archive should be placed (/dev/rmt0 in this example).
Now you can read the table of contents from the archive like this:
example% tar tvf /dev/rmt0 display table of contents of the archive (access user-id/group-id size mod. date filename) rw-r--r-- 1677/40 2123 Nov 7 18:15:1985 ./archive/test.c ... example%
You can extract files from the archive like this:
example% tar xvf /dev/rmt0 extract files from the archive messages from tar example%
If there are multiple archive files on a tape, each is separated from the following one by an EOF marker. tar does not read the EOF mark on the tape after it finishes reading an archive file because tar looks for a special header to decide when it has reached the end of the archive. Now if you try to use tar to read the next archive file from the tape, tar does not know enough to skip over the EOF mark and tries to read the EOF mark as an archive instead. The result of this is an error message from tar to the effect:
tar: blocksize=0
This means that to read another archive from the tape, you must skip over the EOF marker before starting another tar command. You can accomplish this using the mt.1 command, as shown in the example below. Assume that you are reading from /dev/nrmt0.
example% tar xvfp /dev/nrmt0 read first archive from tape messages from tar example% mt fsf 1 skip over the end-of-file marker example% tar xvfp /dev/nrmt0 read second archive from tape messages from tar example%
Finally, here is an example using tar to transfer files across the Ethernet. First, here is how to archive files from the local machine (example) to a tape on a remote system (host):
example% tar cvfb - 20 filenames | rsh host dd of=/dev/rmt0 obs=20b messages from tar example%
In the example above, we are creating a tarfile with the c key letter, asking for verbose output from tar with the v option, specifying the name of the output tarfile using the f option (the standard output is where the tarfile appears, as indicated by the `-' sign), and specifying the blocksize (20) with the b option. If you want to change the blocksize, you must change the blocksize arguments both on the tar command and on the dd command.
Now, here is how to use tar to get files from a tape on the remote system back to the local system:
In the example above, we are extracting from the tarfile with the x key letter, asking for verbose output from tar with the v option, telling tar it is reading from a pipe with the B option, specifying the name of the input tarfile using the f option (the standard input is where the tarfile appears, as indicated by the `-' sign), and specifying the blocksize (20) with the b option.
Neither the r option nor the u option can be used with quarter-inch archive tapes, since these tape drives cannot backspace.
There is no way to ask for the nth occurrence of a file.
Tape errors are handled ungracefully.
The u option can be slow.
There is no way selectively to follow symbolic links.
When extracting tapes created with the r or u options, directory modification times may not be set correctly.
Files with names longer than 100 characters cannot be processed.
Filename substitution wildcards do not work for extracting files from the archive. To get around this, use a command of the form:
tar xvf... /dev/rst0 `tar tf... /dev/rst0 | grep 'pattern'`
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97