[Techtalk] Help? tar(1) -X Option Not Working

Telsa Gwynne hobbit at aloss.ukuu.org.uk
Sat Aug 31 13:06:38 EST 2002

On Fri, Aug 30, 2002 at 12:05:05PM -0700 or thereabouts, Kai MacTane wrote:
> I'm backing up a bunch of stuff by tar(1)ing it up and FTPing it to another 
> machine. I've got a couple of files, listing the stuff to be included and 
> the stuff to be excluded. Using tar's -T and -X flags to direct it to these 
> files, I find that it tars everything in the include file, but doesn't omit 
> the stuff from the exclude file.
> I've pored over the man page and it looks like I've got the syntax right. 

The tar manual page is not, unfortunately, too useful. It is,
I think, almost certainly provided by your distribution. (Go
on. Tell me you're using LFS now :)) And if it's Red Hat, I
bet they are using the Debian-provided manual page. GNU tar
has all its information in the info format (of course..) and 
doesn't come with a man page. But its info pages are huge. Checking 
on something for this reply, I have just found an entire set of 
(useful) nodes I didn't know about. 

Also, the man page and the info file differ on whether equals 
signs are needed in the command, and I still don't know whether 
this matters or not. So for tar, I tend to use the info files.

> Can anyone advise me on this? Here are the files and the command I'm using.
> tar cvzf /backup/BackupFile -X /etc/exclude -T /etc/include

You're not alone with this. See also:
...which I know about in turn because I ran into similar problems
and was about to enter a very similar bug before I found someone
already had.

That bug doesn't involve --exclude-from, but it does involve --exclude.

> I've also tried using --exclude-from=/etc/include, with no change in 
> observed behavior. Moving the -X after the -T also has no effect. Either 

I tend to stick either to short options or to "traditional" options
or to long-opts. It's probably not true, but I have the impression
that mixing and matching is a recipe for disaster. (See the tar
info node where it gives about 13 ways to perform the same action
and then one or two which _look_ the same, but don't...)

As a wild guess, I wonder whether the mention of "PATTERN" in
"info tar" is relevant:

  '-X FILE'
       Causes 'tar' to ignore files that match the patterns listed in

     Use the '--exclude-from=FILE-OF-PATTERNS' option to read a list of
  patterns, one per line, from FILE; 'tar' will ignore files matching
  those patterns.  Thus if 'tar' is called as 'tar -c -X foo .' and the
  file 'oo' contains a single line '*.o', no files whose names end in
  '.o' will be added to the archive.

It's specifically saying "pattern" and by that it means the sort
of globbing you use in the bash shell. It does not mean regexps proper. 
(Which I discovered looking at the nodes "Controlling Pattern-Matching 
with the 'exclude' Options" and "Problems with Using the 'exclude' 

I suspect the answer is in those. It's far too long to paste in
though. Particularly cos my editor thinks backtick is a special
character, and there's backticks all through it :) 

> When tar starts, it says:
>     tar: Removing leading `/' from absolute path names in the archive
> I've tried removing the leading slashes in the exclude file to match, and 
> that also has no effect.

Does bash interpret / marks as part of a pattern? If so, see above.
I think the "Removing leading /" is to aid in restoring: you don't
end up overwriting /etc, /usr and so on unless you specifically
sit in the root directory to do it. I'm not very sure about this

> Can anyone tell me what I'm doing wrong? I'm using GNU tar version 1.13.

I hate to say it, but I think trusting the man page which didn't
come with the GNU package but instead was slapped in by the distro 
is the problem. It's incomplete. You know the "the info page is the 
authoritative reference" comment you get in some GNU packages' man 
pages? With tar, it is _definitely_ true. Set aside at least an hour 
to navigate and read it all, but do read info tar, particularly the 
two nodes I mentioned above.

I found it fascinating, actually :) I've come to really appreciate
some of the info that you get with GNU packages. Loads more than
the man pages, and tutorials and examples that aren't always stuff
that should go in the man pages. Man pages are great for their
own reasons, but info often has so much more.


More information about the Techtalk mailing list