Go to the previous, next section.

Local file selection

(This message will disappear, once this node revised.)

Local file selection

-C dir
--directory dir
Change to directory dir.

This option causes tar to change into the directory dir before continuing. This option can be interspersed with the files tar is to work on. For example,

tar -c iggy ziggy -C baz melvin

will place the files `iggy' and `ziggy' from the current directory on the tape, followed by the file `melvin' from the directory `baz'. This option is especially useful when you have several widely separated files that you want to store in the same directory in the archive.

Here, the file `melvin' is recorded in the archive under the precise name `melvin', not `baz/melvin'. Thus, the archive will contain three files that all appear to have come from the same directory; if the archive is extracted with plain `tar -x', all three files will be created in the current directory.

Contrast this with the command:

tar -c iggy ziggy bar/melvin

which records the third file in the archive under the name `bar/melvin' so that, if plain `tar -x' is used, the third file will be created in a subdirectory named `bar'.

Suppose that, without changing your current directory, you want to call tar to dump files from `/users/ctd/dipp' say. Then `--directory=directory' (`-C directory') is for you. You could do things like:

tar cfC archive.tar /users/ctd/dipp .

(the `.' means the current directory, once the `--directory=directory' (`-C directory') obeyed).

Some people might want some option to extract everything from an archive in the current directory, ignore directory structure in the archive. This is so rarely proper that I doubt such an option would be really useful. It would only help getting around improper tar usage, it might even encourage improper usage. In general, `--directory=directory' (`-C directory') might be used to produce archives with a cleaner structure in the first place.

-T filename
--files-from=filename
Get names to extract or create from file filename.

Instead of taking the list of files to work on from the command line, the list of files to work on is read from the file filename. If filename is given as `-', the list is read from standard input. Note that using both `-T -' and `-f -' will not work unless you are using the `--create' (`-c') command.

This is typically useful when you have generated the list of files to archive with find.

--null
This option causes `--files-from=file-of-names' (`-T file-of-names') to read file names terminated by a NUL instead of a newline, so files whose names contain newlines can be archived using `--files-from=file-of-names' (`-T file-of-names'). The `--null' option is just like the one in GNU xargs and cpio, and is useful with the `-print0' predicate of GNU find. In tar, `--null' also causes `--directory=directory' (`-C directory') options to be treated as file names to archive, in case there are any files out there called `-C'.

--exclude=file
Exclude file file.

-X file
--exclude-from=file
Exclude files listed in file.

This option causes tar to read a list of regular expressions (in shell wildcard syntax), one per line, from file; tar will ignore files matching those regular expressions. Thus if tar is called as `tar -c -X foo .' and the file `foo' contains a single line `*.o', no files whose names end in `.o' will be added to the archive. Multiple `--exclude=pattern' options may be given.

-P
--absolute-names
Do not strip leading /s from file names.

By default, GNU tar drops a leading `/' on input or output. This option turns off this behavior; it's equivalent to changing to the root directory before running tar (except it also turns off the usual warning message).

-l
--one-file-system
Stay in local filesystem when creating archive.

This option causes tar to not cross filesystem boundaries when archiving parts of a directory tree. This option only affects files that are archived because they are in a directory that is archived; files named on the command line are archived regardless, and they can be from various file systems.

This option is useful for making full or incremental archival backups of a filesystem, as with the Unix dump command.

Files skipped due to this option are mentioned on standard error.

-K name
--starting-file=name
Begin at file name in the archive.

The `--starting-file=name' (`-K name') option causes tar to begin extracting or listing the archive with the file filename, and to consider only the files starting at that point in the archive. This is useful if a previous attempt to extract files failed when it reached filename due to lack of free space. (Assuming, of course, that there is now free space, or that you are now extracting into a different file system.)

-N date
--newer=date
--after-date=date
Only store files newer than date.

This option causes tar to only work on files whose modification or inode-changed times are newer than the date given. The main use is for creating an archive; then only new files are written. If extracting, only newer files are extracted.

Remember that the entire date argument must be quoted if it contains any spaces.

The date is parsed using getdate.

Changing the Names of Members when Archiving

Go to the previous, next section.