find command to omit directories (136 Views)
Reply
Super Advisor
Ratzie
Posts: 852
Registered: ‎01-10-2002
Message 1 of 6 (136 Views)
Accepted Solution

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

Please use plain text.
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 2 of 6 (136 Views)

Re: find command to omit directories

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


Pete



Pete
Please use plain text.
Honored Contributor
Graham Cameron_1
Posts: 542
Registered: ‎04-16-2001
Message 3 of 6 (136 Views)

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.
Please use plain text.
Honored Contributor
Umapathy S
Posts: 970
Registered: ‎12-04-2001
Message 4 of 6 (136 Views)

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!
Please use plain text.
Honored Contributor
Denver Osborn
Posts: 1,749
Registered: ‎06-23-2000
Message 5 of 6 (136 Views)

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
Please use plain text.
Honored Contributor
Peter Nikitka
Posts: 1,575
Registered: ‎02-10-2003
Message 6 of 6 (136 Views)

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"
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation