Previous Table of Contents Next


Arguments

The following list describes the arguments that may be passed to the tar command.

block Specifies the blocking factor for raw devices. The default is set to 1. The possible block sizes range from 1 to 64.
device The name of the device to be used for the archive. Each system usually has multiple device drivers for each physical media device. The following table lists some of the more popular drives.
D (Drive) Description
/dev/rmt/0m Raw magnetic tape, 1600 bpi.
/dev/rmt/0h Raw magnetic tape, 6250 bpi.
/dev/mt/0m Magnetic tape, 1600 bpi.
/dev/mt/0h Magnetic tape, 6250 bpi.
/dev/mt/ctape Cartridge tape.
/dev/ctape Cartridge tape.
/dev/diskette Floppy diskette.
 
The possible speeds for 9-track tapes are:
 
S (Speed) BPI (Bytes per inch) Rating
l 800 BPI
m 1600 BPI
h 6250 BPI
 
Use these speed letters to replace the s in the ds option.
BSD (Berkeley)
D (Drive) Description
/dev/rmt0 Raw magnetic tape, the default drive. (rmt8)
/dev/rmt8 Raw magnetic tape, 6250 bpi, rewind.
/dev/rmt12 Raw magnetic tape, 6250 bpi, no rewind.
/dev/rmt16 Raw magnetic tape, 6250 bpi, rewind.
/dev/rmt20 Raw magnetic tape, 6250 bpi, no rewind.
/dev/rst0 Raw SCSI cartridge drive. Usually rst8.
/dev/rst4 Raw SCSI. QIC 02 format.
/dev/rst8 Raw SCSI. QIC 24 format.
/dev/rct0 Raw cartridge tape.
/dev/rct4 Raw QIC 02 cartridge tape.
/dev/rct8 Raw QIC 24 cartridge tape.
filelist The list of filenames and/or directories you wish to archive or unarchive (extract).

EXAMPLES

Some examples of how to use tar follow.

1.  Archiving more than one directory. To archive more than one directory you can use the -C option of BSD. For System V you just specify the list of directories. The -C allows short relative pathnames. The following example is for a BSD tar. It copied the bin subdirectory and the sibling directory of jim/bin to tape.
cj> tar cf -C ./bin -C ../jim/bin /dev/rmt8
2.  Copying one directory structure to a new directory location on disk.
cj> cd fromdir
cj> tar cf - . | ( cd todir; tar xf - )

The first cd command changes your working directory to where you want to copy from, such as your HOME directory. The tar command creates a tar file to the standard output. The output is piped to a subshell which changes directories (cd) to the directory you want to copy the files to; for example, a new HOME directory on a different file system. The second tar command extracts the files back out into a hierarchical structure.
3.  Archiving the current directory. This example shows how to save your home directory to tape on a System V UNIX machine.
cj> tar -cvf /dev/rmt/0m.
4.  Listing contents of an archive tape. The following example lists the contents stored on tape from a previous tar command on a BSD UNIX machine.
cj> tar -tvf /dev/rmt8 .
rwxr-xr-x 901/100        1321      Aug 19 15:54:1989   ./
rwxr-xr-x 901/100        1321      Aug 19 15:54:1989   ./bin/
.
.
.

The format is,
permissions uid/gid      size      date   time         file
5.  Extracting files from an archive tape. The following example assumes you are on a System V system.
cj> cd desired_directory
cj> tar -xvf /dev/rmt/0m
x ./file1, 199 bytes, 1 tape blocks
.
.
.
6.  The find command will locate all files newer than the .lastsave file and print the pathname. The output of the find command is sent to the tar command and the files are added to the arc archive file. You must create the .lastsave file the first time you run the find command. Each time you run find you must touch .lastsave so find will have a time to compare against for the next save.
cj> touch 11160101 .lastsave # set date back a few days Nov 11 1:00AM
cj> find . -newer .lastsave -print | tar -rf arc -
cj> touch .lastsave

DIAGNOSTICS AND BUGS

The tar command does have its shortcomings. The following list provides a brief description of those features that would be nice to have.

There is no way to recover a specific version of a file.
If a tape error occurs tar usually aborts. Error recovery would help.
The -u option is often extremely slow.
The -b option should not be used if later updates are to be applied.
Empty directories and special files are not archived.
The magnetic tape device driver cannot perform backspaces on raw magnetic tapes.

RELATED COMMANDS

Refer to the cpio command described in Module 25.

RELATED FILES

The tar command uses a temporary file to perform its processing.

/tmp/tar* The temporary work file tar uses to perform its task.

APPLICATIONS

The most common use of tar is to create archive tapes and extract files when needed. The tar command is more sophisticated than the cpio program. It can update the existing archive file without having to rewrite the file from the beginning. It can also be used to copy directory structures from one directory to a new directory.

TYPICAL OPERATION

In this activity you use the tar command to archive a directory structure to a temporary file. If you can arrange to use the tape drive on your system, you might want to try this activity using the device name of your system's tape drive. But for simplicity we use a file on the system to archive your files. Begin at the shell prompt in your HOME directory.

1.  Type tar -cvf /tmp/mylogin.arc . and press Return. This command archives your current directory creating an archive file named /tmp/mylogin.arc.
2.  Type col < /tmp/mylogin.arc | pg and press Return. Notice the file is in a readable format. This is the archive file you just created. If binary or data files have been archived, your display may be garbled and/or your terminal may hang. That is why you use the col command.
3.  Type q and press Return to exit pg.
4.  Type tar -tvf /tmp/mylogin.arc and press Return to list the filenames of each file contained in the archive file.
5.  Turn to Module 31 to continue the learning sequence.


Previous Table of Contents Next