Exclude file in tar on SCO Unix

I am using tar to back up a directory in SCO Openserver 5.  I want to exclude a directory in that directory.  I don't want to back it up.  How do I accomplish this using tar.

example:

tar cvf /backup/tarfile /usr/test/ac
this backs up everthing in /usr/test/ac

I want to back up everything but a directory called mar in the "ac" directory.
foxhelpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikelfritzCommented:
list=`find /usr/test/ac | grep -v /mar/`
tar cvf /backup/tarfile $list
0
foxhelpAuthor Commented:
tried that, it still backups up the "mar" directory.  Does list= put "mar" in a file or something that I can look at?  when I do the tar after the list, it still shows me mar as a directory that is being backed up.
0
mikelfritzCommented:
It will backup the directory - but it will be empty - no files under /usr/test/ac/mar will be included.

list=`find /usr/test/ac | grep -v /mar/`

creates a variable that contains the files you want - "grep -v" will exclude "/mar/*" from the list.

try:
list=`find /usr/test/ac | grep -v /mar/`
echo $list

that should show you what it will backup.

If you want to exclude the directory as well you can use this (with a caveat):
list=`find /usr/test/ac | grep -v /mar`

This will exclude both the /usr/test/ac/mar directory and contents, but also any file starting with "mar" in the /usr/test/ac directory.
0
mikelfritzCommented:
You could also get gnu tar for openserver - I think it supports the exclude directives:

ftp://ftp2.sco.com/pub/skunkware/osr5/fileutil/tar/
0
mikelfritzCommented:
Found this post from a few years ago - seems I couldn't make the GNU version play nice - it does not work like others wrt the --exclude:
http://www.experts-exchange.com/OS/Unix/SCO_Unix/Q_25086206.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.