Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

How to exclude a directory using "find"

 
Highlighted
Regular Advisor

How to exclude a directory using "find"

In a script called by cron i have a line that checks for any new tar files but I want it to exclude a mounted filesystem /share01

This command finds all the tar files
#find / -name '*.tar' -mtime -1

I've been trying to modify it to exclude /share01 but need help.


I've tried this next command but it doesnt exclude /share01:

#find / -name '*.tar' -mtime -1 ! -path "/share01/*"

Any tips?
5 REPLIES 5
Highlighted
Honored Contributor

Re: How to exclude a directory using "find"

Highlighted
Regular Advisor

Re: How to exclude a directory using "find"

Thanks ashan,

Ive been looking at similiar threads but cannot get the correct syntax.

I tried the following but no joy
find / -name '*.tar' -path /share01 -prune

Any ideas?
Highlighted
Honored Contributor

Re: How to exclude a directory using "find"

Hi again

So, lets try this command

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


Have fun!!!
a warrior never quits
Highlighted
Regular Advisor

Re: How to exclude a directory using "find"


The /share01 directory is a remotely mounted NFS directory so I just told it to search local directories instead.

#find / ! -local -prune -o -name '*.tar' -mtime -1 -print

It's a work-around but im pleased.
thanks for your assistance ahsan
Highlighted
Trusted Contributor

Re: How to exclude a directory using "find"

I don't trust the prune command. Instead I make the list of files and pipe it through grep -v.

LIST=`find / yadda yadda | grep -Ev "^\/excludedir"`

for X in $LIST
do
commands
commands
done

steve