exclude option for tar

Hi Folks,

I'm having trouble getting this to work:

96 8:22 tar cvf /Vol /U1/bills.filtered.tarfile.tar --exclude '*.doc' ./*
97 8:23 tar cvf /Vol /U1/bills.filtered.tarfile.tar --exclude '\*\.doc' ./*
98 8:24 h
99 8:25 tar cvf /Vol /U1/bills.filtered.tarfile.tar --exclude '*.doc' ./*
100 8:27 tar cvf /Vol /U1/bills.filtered.tarfile.tar --exclude *.doc ./*
101 8:27 tar cvf /Vol /U1/bills.filtered.tarfile.tar --exclude=*.doc ./*


None of these have the desired effect of excluding .doc files... what am I
doing wrong?

Thanks

Bill

G4 Laptop, Mac OS X (10.4.11)

Posted on Mar 11, 2008 8:42 AM

Reply
14 replies

Mar 11, 2008 4:41 PM in response to bixote

Hi,

I tried a simple test and all of the following forms of exclude worked for me:
--exclude '*.doc'
--exclude "*.doc"
--exclude='*.doc'
--exclude="*.doc"

(leaving the all quotes off only excluded doc files in the current working directory but not in sub folders)

Can you try hardwiring the path to the tar file as a test? It's the only other obvious difference from my example that I see.

--
Cole

Mar 11, 2008 6:48 PM in response to Cole Tierney

Descending deep into the underbelly of Unix history, there have been an almost infinite number of implementations of tar, by almost as many organizations. One of the differences has been whether the command part of the invocation begins with or without a dash. Some organizations so wanted everyone to adopt their way that they either produced an error or berated you in some way if you dared try the other syntax.

Because it long ago reached the point where there clearly was never going to be one "right" way to do it, most competent tar programmers resorted to accepting either form.

The current version of GNU tar included with OSX behaves this way (thankfully).

Tar isn't the only Unix command with this sort of history, the above story applies to ar as well, although they haven't gotten quite as far along the evolutionary path as the tar authors yet (there are still ar versions that call you names if you deign to use, or not use, the dash, depending on their religion).

Mar 12, 2008 10:06 AM in response to Cole Tierney

Another question: Did your final solution also include wild cards to your target tar file? When I try a similar path, tar fails with:
tar: /Vol /TB/file.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

ls /Vol /TB/ expands correctly. When I write out the whole path to my file, tar is happy. Just want to be sure this doesn't sneak up on you again later on.

--
Cole

Mar 12, 2008 1:40 PM in response to Cole Tierney

Another question: Did your final solution also include wild cards to your target tar file? When I try a similar path, tar fails with:
tar: /Vol /TB/file.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

The shell can't expand "/Vol /TB/file.tar" because it doesn't exist.
ls /Vol /TB/ expands correctly. When I write out the whole path to my file, tar is happy. Just want to be sure this doesn't sneak up on you again later on.

It can expand "/Vol /TB/" when you run ls on it because it's there.

You could run

tar cf $(echo /Vol/TB)/file.tar ...

if you had to, but just supplying the path might be easier.

Mar 12, 2008 2:01 PM in response to corbaguy

{quote:title=corbaguy wrote:}The shell can't expand "/Vol /TB/file.tar" because it doesn't exist.{quote}

That's why I'm curious to find out how bixote was able to make it work. The original post lists 5 earlier attempts, 4 of which would've worked had the path to the tar file not contained wild cards. My theory is the exclude option may have been a red herring and not the source of the original problem.

--
Cole

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

exclude option for tar

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.