tar: how to exclude subdirectories?

If i have a bunch of directories that i normally backup with this:
tar cvhf /dev/rmt/0 /export/home

How can i exclude certain subdirectories under the /export/home?

tar cvhf /dev/rmt/0 /export/home | grep -v 'test' ? will that exclude anything named test, and any subdirectories under test?

Theres a link a thread here

Hmm, i followed that thread, came up with some useful info

BUT

i ran the following:

find /export/home /etc /usr | egrep -v "test/" > list.txt
tar cvhf /dev/rmt/0 'cat list.txt'

doesn't work. doesn't like the cat in there. what am i doing wrong?

I think you're using single quotes when you want back quotes.
Don't use ' when you want `

aha, this worked:

#>find /export/home /etc /usr ! -type d -print | egrep 'test/' > Exclude.txt

then
#> tar cvfX backup.tar Exclude.txt /export/home /etc /usr

2 step process. Actually 3 cuz I have to put it on tape, but could put on tape in the 2nd process, skip the tar file.

Darn, this got me before!~ on the date command. THe confusing thing is that ' works in the egrep part of the statement, but have to use ` for the cat part of it! but it says argument listing too long. hmm.

tar cvf /dev/rmt/0 `cat listing.txt` is what i put in. what do you think it's not getting?

This trick will not work for lengthy lists of files. Yours is too long.

Well, using the find files ! -type d -print | egrep 'test/' > listing.txt
and then tar cvfX /dev/rmt/0 listing.txt files worked.

Was hoping to find an easier way, but if it works I'll use it!

Thanks so much
:slight_smile: