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.


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.
Who is Participating?
mikelfritzConnect With a Mentor Commented:
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:
list=`find /usr/test/ac | grep -v /mar/`
tar cvf /backup/tarfile $list
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.
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.

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.
You could also get gnu tar for openserver - I think it supports the exclude directives:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.