Read and write tape archive files (UNIX)
Create a new archive:
tar -c [-b blocking] [-f file] [-vw] [filename...]
Write named files to the end of an archive:
tar -r -f file [-b blocking] [-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...]
- -b blocking
- Specify the blocking factor for tape
records. The default is 1. This option should be used
only with raw magnetic tape archives.
- -c
- Create a new archive. Writing begins at the beginning of the archive,
instead of after the last file.
- -f file
- Specify the name of the archive to use
instead of the default, which is standard output. If the dash
character (-) is specified as a filename, tar
writes to the standard output or reads from the standard input, whichever
is appropriate for the options given. Thus, tar can be used as
the head or tail of a pipeline.
- -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
- Don't restore modification times. The modification time of the file will
be the time of extraction. This option is invalid with the
-t option.
- -o
- Cause extracted files to take on the user and group identifier of the user
running the program rather than those on the archive. This option is valid
only with the -x option.
- -r
- Write named files to the end of the archive specified in the required
-f file option.
- -t
- List the names of all of the files in the archive.
- -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
- 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
- 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 will overwrite all earlier
ones.
- filename
- The pathname of the file to be archived.
The tar utility reads and writes archive files that conform
to the Archive/Interchange File Format specified in POSIX Std/1003.1-1988.
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]
The controlling terminal (/dev/tty) is used to prompt
the user for information when either or both the -i or
-y options are specified.
cpio,
pax,
scsi_util,
tape