Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

find command to omit directories

SOLVED
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
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
Highlighted
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"