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


6.4 Excluding Some Files

@UNREVISED

To avoid operating on files whose names match a particular pattern, use the --exclude=pattern or --exclude-from=file-of-patterns (-X file-of-patterns) options.

--exclude=pattern
Causes tar to ignore files that match the pattern.

The --exclude=pattern option prevents any file or member whose name matches the shell wildcard (pattern) from being operated on. For example, to create an archive with all the contents of the directory `src' except for files whose names end in `.o', use the command `tar -cf src.tar --exclude='*.o' src'.

A pattern containing `/' excludes a name if an initial subsequence of the name's components matches pattern; a pattern without `/' excludes a name if it matches any of its name components. For example, the pattern `*b/RCS' contains `/', so it excludes `blob/RCS' and `.blob/RCS/f' but not `blob/RCSit/RCS' or `/blob/RCS', whereas the pattern `RCS' excludes all these names. Conversely, the pattern `*.o' lacks `/', so it excludes `.f.o', `d/f.o', and `d.o/f'.

Other than optionally stripping leading `/' from names (see section 6.8.2 Absolute File Names), patterns and candidate names are used as-is. For example, trailing `/' is not trimmed from a user-specified name before deciding whether to exclude it.

You may give multiple `--exclude' options.

--exclude-from=file
-X file
Causes tar to ignore files that match the patterns listed in file.

Use the `--exclude-from=file-of-patterns' option to read a list of shell wildcards, 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.

@FIXME{do the exclude options files need to have stuff separated by newlines the same as the files-from option does?}


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