tar and --include

Tim Kientzle kientzle at freebsd.org
Thu May 20 05:44:17 UTC 2010


b. f. wrote:
> Martin McCormick wrote:
>>        What I discovered was that --include doesn't appear to
>> do anything at all. The example in the man page shows using it
>> to filter an existing archive ...  I never
>> tried that since that is not what was needed here.

The --include directive was designed to support the
case of filtering an existing archive.  GNU tar has
no equivalent to bsdtar's @archive feature and hence
has no real need for --include.

If you really need detailed control over which
files get archived, I do recommend learning how
to use find(1) in conjunction with tar.  (Just remember
to use tar's -n option!)

> There certainly seems to be a bug here, either in the documentation or
> the implementation.  The example you mention works as expected for me
> on 9-CURRENT, but the --include option fails on, for example:
> 
> tar -cvf new.tar --include='baz'  foo/bar

In your example here, the first item
tar inspects is "foo/bar", which does not match
the pattern and therefore is not included.
Excluding a directory excludes everything
in the directory.

The net result is the same as if you had specified:
    tar -cvf new.tar --exclude='foo/bar' foo/bar

Cheers,

Tim



More information about the freebsd-questions mailing list