tar and --include

2 views
Skip to first unread message

Martin McCormick

unread,
May 19, 2010, 11:50:38 AM5/19/10
to freebsd-...@freebsd.org
A few days ago, I asked about the --include directive in tar
after things didn't quite work the way the man page seemed to
indicate. One might get the impression that if --include or
--include='*pattern*' was added to a tar command, tar would only
archive what was in the pattern and not archive everything as
its default operation.

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 and make a tar file of what was in
the existing archive that also matched the pattern. I never
tried that since that is not what was needed here.

What turned out to work very well was to use the feature
in tar that lets one exclude a whole list of patterns in a
designated file. You just put in what shouldn't be in the
archive and it appeared to work fine.

The --include directive only seems to exist in the
FreeBSD form of tar. I tried a Linux system's tar man page and
it is not there but both support the -X path/filename for a list
of exclusion patterns.

Martin McCormick WB5AGZ Stillwater, OK
Systems Engineer
OSU Information Technology Department Telecommunications Services Group
_______________________________________________
freebsd-...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questi...@freebsd.org"

--
You received this message because you are subscribed to the Google Groups "ml-freebsd-questions" group.
To post to this group, send email to ml-freebsd...@googlegroups.com.
To unsubscribe from this group, send email to ml-freebsd-quest...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ml-freebsd-questions?hl=en.

b. f.

unread,
May 19, 2010, 10:26:37 PM5/19/10
to freebsd-...@freebsd.org, Martin McCormick, kien...@freebsd.org
Martin McCormick wrote:
>A few days ago, I asked about the --include directive in tar
>after things didn't quite work the way the man page seemed to
>indicate. One might get the impression that if --include or
>--include='*pattern*' was added to a tar command, tar would only
>archive what was in the pattern and not archive everything as
>its default operation.
>
> 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 and make a tar file of what was in
>the existing archive that also matched the pattern. I never
>tried that since that is not what was needed here.

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

when the pattern baz should match files in the directory foo/bar,
regardless of whether baz contains wildcards or not, or when baz is
anchored at the start or not. The output is garbage.

>

...

> The --include directive only seems to exist in the
>FreeBSD form of tar. I tried a Linux system's tar man page and
>it is not there but both support the -X path/filename for a list
>of exclusion patterns.
>

I don't see your point here. For the sake of compatibility, bsdtar
aims to support GNU tar features, but not _only_ those features. The
--include option is useful for specifying files and directories to
include without having to anchor inclusion patterns from the start,
and without having to use tar -I/-T with an inclusion file, or tar in
conjunction with find(1) -- so the option should be fixed so that it
works.

b.

Tim Kientzle

unread,
May 20, 2010, 1:43:48 AM5/20/10
to bf1...@gmail.com, Martin McCormick, freebsd-...@freebsd.org
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

b. f.

unread,
May 20, 2010, 2:06:48 AM5/20/10
to Tim Kientzle, Martin McCormick, freebsd-...@freebsd.org
On 5/20/10, Tim Kientzle <kien...@freebsd.org> wrote:
> 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.
>

...

>
>> 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

tar(1) states "The --include option is especially useful when
filtering archives." If I understand your comments correctly, this
statement should be changed to state that the option is, in fact,
_only_ useful when filtering archives. The current description of the
option is misleading.


b.
Reply all
Reply to author
Forward
0 new messages