Operating System - HP-UX
1819791 Members
3274 Online
109607 Solutions
New Discussion юеВ

Excluding multiple directories & files using FIND command

 
Dave Geiger
Occasional Advisor

Excluding multiple directories & files using FIND command

Hi All

I am trying to use the find command and exclude multiple directories and files.

So can you suggest me the syntax of excluding multiple directories and files using the find command

help is appreciated.

Thanks
Dave
5 REPLIES 5
Rodney Hills
Honored Contributor

Re: Excluding multiple directories & files using FIND command

find / ! \( -path "/dev/*" -path "/tmp/*" \) -print

will walk through entire file system except for /dev and /tmp

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: Excluding multiple directories & files using FIND command

To exclude specific file names

find / ! \( -name "core" -name "*.c" \) -print

This will exclude files named "core" or ending with .c.

HTH

-- Rod Hills
There be dragons...
Senthil Prabu.S_1
Trusted Contributor

Re: Excluding multiple directories & files using FIND command

Hello Dave,
you can use the find command with following option to exclude directories;

find . -name $DIRNAME -prune -o -print

where, $DIRNAME is the name of the directory to be excluded.

HTH,

Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Arunvijai_4
Honored Contributor

Re: Excluding multiple directories & files using FIND command

To Exclude DIR1, DIR2 and DIR3 from list simply use:

find / -type d \( -name DIR1 -o -name DIR2 -o -name DIR3 \) -prune -o
-type d -print

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Steve Post
Trusted Contributor

Re: Excluding multiple directories & files using FIND command

Here's another obvious way. Find all the stuff, then remove the pieces you want to exclude.

I want to backup filesystems /a /b and /d.
I want to skip filesystem /c, and directories: /a/skip1, /b/notthis.

find /a /b /d -print | grep -Ev "^\/a\/skip1|^\/b\/notthis" > answer.txt

Or....
find /a /b /d -print > bigfile
cat bigfile | grep -Ev "^\/a\/skip1|^\/b\/notthis" > answer.txt

Or...
find / -print > bigfile
cat bigfile | grep -Ev "^\/c|...blah blah.."

^ ==== anchor search to beginning of string.
\/ === really search for a forward slash.
| ==== the OR command.