Operating System - HP-UX
1752815 Members
6026 Online
108789 Solutions
New Discussion юеВ

Re: find command to omit directories

 
Go to solution
Ratzie
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 5
Pete Randall
Outstanding Contributor

Re: find command to omit directories

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


Pete



Pete
Graham Cameron_1
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.
Umapathy S
Honored Contributor
Solution

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!
Denver Osborn
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
Peter Nikitka
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"