Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ The tar Manual: DRAFT - 2. The Different Operations tar Can Perform

Media Vault

Software Library

Restoration Projects

Artifacts Sought

The tar Manual: DRAFT - 2. The Different Operations tar Can Perform

Go to the first, previous, next, last section, table of contents.


2. The Different Operations tar Can Perform

One program, tar, is used to create an archive, to extract files from an archive, to modify an archive, or to list the contents. Each time you run tar, you must give a command to specify which one of these things you want to do.

The command must always be in the first argument to tar. This argument can also contain options (see section 3. Options That Change How tar Works). For compatibility with Unix tar, the first argument is always treated as containing command and option letters even if it doesn't start with `-'. Thus, `tar c' is equivalent to `tar -c': both of them specify the `-c' command to create an archive.

In addition, a set of long-named options are provided which can be used instead of or inter-mixed with the single-letter flags. The long-named options are meant to be easy to remember and logical, while the single letter flags may not always be. Long-named options are preceded by a `+'. In the list of single-letter commands below, each corresponding long-named option is listed next to it, in parentheses.

The remaining arguments to tar are either options, if they start with `-' or `+', or files to operate on.

The file names that you give as arguments are the files that tar will act on -- for example, they are the files to put in the archive, or the files to extract from it. If you don't give any file name arguments, the default depends on which command you used. Some commands use all relevant files; some commands have no default and will report an error if you don't specify files.

If a file name argument actually names a directory, then that directory and all files and subdirectories in it are used.

Here is a list of all the tar commands:

`-c'
`+create'
This command tells tar to create a new archive that contains the file(s) specified on the command line. If you don't specify files, all the files in the current directory are used. If the archive file already exists, it is overwritten; the old contents are lost.
`-d'
`+compare'
`+diff'
This command causes tar to compare the archive with the files in the file system. It will report differences in file size, mode, owner, and contents. If a file exists in the archive, but not in the file system, tar will report this. If you specify file names, those files are compared with the tape and they must all exist in the archive. If you don't specify files, all the files in the archive are compared.
`-r'
`+append'
This command causes tar to add the specified file(s) to the end of the archive. This assumes that the archive file already exists and is in the proper format (which probably means it was created previously with the tar program). If the archive is not in a format that tar understands, the results will be unpredictable. You must specify the files to be used; there is no default.
`-t'
`+list'
This command causes tar to display a list of the files in the archive. If you specify file names, only the files that you specify will be mentioned (but each of them is mentioned only if it appears in the archive).
`-u'
`+update'
This command causes tar to add the specified files to the end of the archive, like `-r', but only when a file doesn't already exist in the archive or is newer than the version in the archive (the last-modification time is compared). Adding files to the end of an archive can be very slow. You must specify the files to be used; there is no default.
`-x'
`+extract'
`+get'
This command causes tar to extract the specified files from the archive. If no file names are given, all the files in the archive will be extracted.
`-A'
`+catenate'
`+concatenate'
This command is used for concatenating several archive files into one big archive file. The files to operate on should all be archive files. They are all appended to the end of the archive file which tar works on. (The other files are not changed). You might be tempted to use cat for this, but it won't ordinarily work. A tar archive contains data which indicates the end of the archive, so more material added to the end with cat would be ignored. This command works because it removes the end-of-archive markers from the middle of the result.
`-D'
`+delete'
This command causes tar to delete the specified files from the archive. This command is extremely slow. Warning: Use of this command on archives stored on magnetic tape may result in a scrambled archive. There is no safe way (except for completely re-writing the archive) to delete files from a magnetic tape.


Go to the first, previous, next, last section, table of contents.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026