We help IT Professionals succeed at work.

'find' - Exclude one directory

leonst asked
I'm trying to backup a SCO UnixWare 7.1.0 system from the shell using find/cpio. Trouble is I don't want to backup one very large directory and I wondered if there is 'find' syntax to do this?

The closest I can get is
find . \( -name 'user1' -prune -o -name '*' \)

(user1 being the directory to be excluded) but this still returns the name of the directory. Is there a way to stop 'find' showing the directory *and* contents?

Thanks in advance for any help.
Watch Question

find . -path './user1' -prune -o -print


Thanks for your response. Unfortunately, on my system the -path switch doesn't exist (I assume that '-path' was meant literally and not as a variable) and a quick look on other systems (http://www.computerhope.com/unix/ufind.htm, http://www.mkssoftware.com/docs/man1/find.1.asp) seems to suggest that most Unices don't support this.

What does '-path' do and is there a way to do it long hand?
My post was based on Linux.

On my Solaris 7 box the following seems to work as you want....

find . -name user1 -prune -o -print

What Unix are you using?

Cheers - Gavin


Spot on, many thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.