[vox-tech] Question about Tar

Jeff Newmiller vox-tech@lists.lugod.org
Tue, 27 May 2003 10:44:20 -0700 (PDT)


On Tue, 27 May 2003, Richard Crawford wrote:

> I've been trying to create a tar file which contains everything in our
> website except files in subdirectories called "message".

This description is ambiguous:

a) if the subdirectory is named "message", exclude all files in it and
   all files in all subdirectories of that directory?

b) in any subdirectory (not the current directory) ignore all files named
   "message"?

> First, I created an exclude file this way:
> 
> # find . -type f -print | egrep 'message*' > dlcmessages

1) Because this is depending on egrep regular expressions rather than
   filename wildcard globbing, it would match strings like "messag",
   "message", "messageee", "whatevermessag", and so on, potentially
   leading to selecting filenames that you actually don't want to end up
   in the exclude list.

2) This output does not include any subdirectories named "message"
   because they are not plain files ("-type f").  This may not be a
   problem if your intended meaning was (b).

3) If your intended meaning was (b), then this will also grab files from
   the current directory, not just subdirectories.

> When I cat the dlcmessages file, I see all of the message files, so I
> assume it assembled the file properly.
> 
> Now, I'm trying to run the tar command.  I've used this:
> 
> # tar -cvf dlctar.tar --exclude-file=dlcmessages .

Do you mean "--exclude-from" option?

> It starts the process without any hiccups, but it doesn't appear to
> exclude the message files that I want to have excluded.

Since your tar syntax above is corrupt yet you say it worked, I suppose
this means you did use "--exclude-from".

There is quite a bit of documentation on "tar" in "info tar".  One thing
to note in the section on "exclude" options is that the patterns tar looks
for are file globbing patterns, not regexp (egrep) patterns. I would hope
this shouldn't make a difference in the absence of wildcard characters,
(as in your dlcexclude file) but it is something to be aware of.

> I've also tried
> 
> # tar -cvfX dlctar.tar exclude .

"-X" is equivalent to "--exclude-from", but here you also use "exclude"
instead of "dlcmessages".  Assuming those two files are the same, there
should be no difference in effect, so something about your expectations
of this command needs to be clarified. Can you give an example directory
structure, with commands and output showing what expectations were not
met and what you wanted?

> with no success.
> 
> According to the documentation I've read, including man tar, this *should*
> work, but it isn't.  What am I doing wrong?

Not sure.  Have you tried a "find"/"tar -T" inclusion approach?  The
exclusion approach ought to work, but breaking out of your box may
illuminate something.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------