System Administration
Showing results for 
Search instead for 
Do you mean 

find command to omit directories

SOLVED
Go to Solution
Super Advisor

find command to omit directories

I need to modify a script that does a find and pipes it to a file, right now
it omits the "lost + found" directory, but I want to add another directory.
How do I do it?
I want to omit the directory db5 as well.

find ./db* -print |grep -v "lost+found" > /tmp/backup.input

5 REPLIES
Outstanding Contributor Outstanding Contributor

Re: find command to omit directories

find ./db* -print |grep -v "lost+found" |grep -v db5 > /tmp/backup.inpu


Pete



Pete
Honored Contributor Honored Contributor

Re: find command to omit directories

I don't think find alone can do this, but you can just extend your grep statement:

find ./db* -print |grep -v -e "lost+found" -e "/db5" > /tmp/backup.input

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Honored Contributor Honored Contributor

Re: find command to omit directories

A slightly modified version
find . -print |egrep -v -e "lost+found|db5" > /tmp/backup.input

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Honored Contributor Honored Contributor

Re: find command to omit directories

and another way...

# vi /tmp/exclude.txt
lost+found
db5

# find ./db* -print |grep -v -f /tmp/exclude.txt >/tmp/backup.input


-Denver
Highlighted
Honored Contributor Honored Contributor

Re: find command to omit directories

Hello,
try

find . \( -name ign1 -prune -o -name ign2 -prune \) -o -print

For a (variable) list of dirs I simply generate the option-arglist for find:
excl='one
two
three'

findopt=$(print "$excl" |
awk 'NR==1 {printf("( -name %s -prune ",$1);next}
{printf("-o -name %s -prune ",$1)}
END {print(")")}')

find . $findopt -o -print
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"