[Previous] [Contents] [Index] [Next]

tar

Read and write tape archive files (UNIX)

Syntax:

Create a new archive:

tar -c [-b blksize] [-f file] [-vw] [filename...]

Write named files to the end of an archive:

tar -r -f file [-b blksize] [-vw] [filename...]

List all the files contained in an archive:

tar -t [-f file] [-v] [filename]

Extract named files from an archive:

tar -x [-f file] [-lmovw] [filename...]

Options:

-[0-7][lmh]
Specify the drive and density.
-A
Append tar files to an archive.
-B
Reblock as we read (for 4.2BSD pipes).
-b blksize
Specify the blocking factor for tape records. The default is 1; the maximum is 20. This option should be used only with raw magnetic tape archives. Normally, the block size is determined automatically when reading tapes.
-C=dir
Change to the directory dir.
-c
Create a new archive. Writing begins at the beginning of the archive, instead of after the last file.
-d
Find the differences between the archive and the filesystem.
-F=file
Run the given script at the end of each tape (implies -M).
-f file
Specify the name of the archive to use instead of the default, which is standard output. If you specify the dash character (-) as a filename, tar writes to the standard output or reads from the standard input, whichever is appropriate for the options given. Thus, you can use tar as the head or tail of a pipeline.
-G
Handle the old GNU-format incremental backup.
-g
Handle the new GNU-format incremental backup.
-h
Dump instead the files that symlinks point to.
-i
Ignore zeroed blocks in archive (means EOF).
-K=name
Begin at file name in the archive.
-k
Don't overwrite existing files when extracting.
-L num
Change tape after writing num * 1024 bytes.
-l
("el") Report if all of the links to the files being archived cannot be resolved. If this option isn't specified, no error messages are written to the standard output. This option is valid only with the -c and -r options.
-M
Create, list, or extract a multivolume archive.
-m
Don't restore modification times. The modification time of the file is the time of extraction. This option is invalid with the -t option.
-N=date
Store only the files that are newer than date.
-O
("Oh") Extract files to standard output.
-o
Write a V7 format archive.
-P
Don't strip leading slashes (/) from filenames.
-p
Extract all protection information.
-R
Show the block number within the archive with each message.
-r
Write named files to the end of the archive specified in the required -f file option.
-S
Handle sparse files efficiently.
-s
Sort the names to extract to match archive.
-T=name
Get the names to extract or create from the file, name.
-t
List the names of all of the files in the archive.
-U
Unlink each file prior to extracting over it.
-u
Append only files that are newer than the copy in the archive.
-V=name
Create an archive with the volume name specified by name.
-v
Be verbose. Usually, tar works silently, but the -v option causes it to print the name of each file it processes, preceded by the option letter. With the -t option, -v gives more information about the archive entries than just the name.
-W
Attempt to verify the archive after writing it.
-w
Print the action to be taken, followed by the name of the file, then wait for the user's confirmation. If you enter a word beginning with y, the action is performed. Any other input means "no". This option is invalid with the -t option.
-X=file
Exclude the globbing patterns listed in file.
-x
Extract named files from the archive. If a named file matches a directory whose contents had been written onto the archive, that directory is recursively extracted. If a named file in the archive doesn't exist on the system, the file is created with the same mode as the one in the archive, except that the set-user-id and set-group-id modes are set only if you have appropriate privileges.

If the files exist, their modes are not changed except as described above. The owner, group, and modification time are restored if possible. If no filename argument is given, the entire contents of the archive is extracted. Note that if several files with the same name are in the archive, the last one overwrites all earlier ones.

-Z
Filter the archive through compress.
-z
Filter the archive through gzip.
filename
The pathname of the file to be archived.

Description:

The tar utility reads and writes archive files. For more information, see the GNU website at http://www.gnu.org/.


Note: The GNU tar is incompatible with the current POSIX standard and with tar programs that follow POSIX. For details, see the GNU documentation.

Examples:

Display a verbose listing of the archive members in dist.tar:

    tar -tvf dist.tar

Copy the contents of the current directory to the floppy drive:

    tar -cf /dev/fd0 .

Make an archive, backup.tar, of all the C source and header files in the current directory:

    tar -cvf backup.tar *.[ch]

Files:

The controlling terminal (/dev/tty) is used to prompt the user for information when either or both the -i or -y options are specified.

Author:

GNU

See also:

bzip2, cpio, gzip, pax

Backing Up and Recovering Data in the Neutrino User's Guide


[Previous] [Contents] [Index] [Next]