Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Find command - Avoid some directories 2

Status
Not open for further replies.

philipose

Programmer
Dec 24, 2003
137
US
Unix gurus,
I am using kshell and am familiar with the unix find command along with its logical expressions.
eg : find / -name "a*" \( ! \( "*.bz2"-o -name "*.gz" \) \) -print

to find all files with a and does not have an extension .bz2 or .gz.

I need to conduct the find excluding some directories, for example i need to avoid find searching in directories /europe and all its subdirectories and /asia/china and all its subdirectories.

Do you have any thoughts?

Thanks in advance
philipose
 
First thoughts, add:

Code:
| grep -v '/europe' | grep -v '/asia/china' etc

to the end of your find command to exclude any of these diectories.

 
i'm still working on it :) and my first thought was as kenCunningham was thinking but i didn't wanted to say it before i finish with what i have!!!

any way i think your command is having something wrong as well!!!

I'll come back to you soon :)
 
What exactly you need this search for? is it inside a script?

ok try this

Code:
find . \( ! \( -name "*.bz2" -o -name "*.gz" \) \) -a -name "a*" -print | grep -v "/europe" | grep -v "/asia/china"
 
oh sorry it should be / (root)

Code:
find / \( ! \( -name "*.bz2" -o -name "*.gz" \) \) -a -name "a*" -print | grep -v "/europe" | grep -v "/asia/china"
 
KenCunningham and khalidaaa,
thanks for your help. i think i misled you a little. if my aim was just to print these directories it would have worked perfectly. unfortunately i needed to have the -exec flag too.

find / \( ! \( -name "*.bz2" -o -name "*.gz" \) \) -a -name "a*" -exec anothershellscript "{}" \;

ie i am sending each of the output of the find command as input to another shell script. maybe something like this might work.

for experimentation purposes you can replace the anothershellscript with echo or type commands.

for each files in `find / \( ! \( -name "*.bz2" -o -name "*.gz" \) \) -a -name "a*" -print | grep -v "/europe" | grep -v "/asia/china"`
anothershellscript "$files"
done

I will try that

Thanks
philipose
 
i don't know exactly what that anothershllscript is!!!

but if it was a backup or an ls command for example, you can pipe as well to that command as in:

find / \( ! \( -name "*.bz2" -o -name "*.gz" \) \) -a -name "a*" -print | grep -v "/europe" | grep -v "/asia/china" | ls -al (or backup -iqf/dev/rmt0)

regards
Khalid
 
find / (whatever criteria) | egrep -v '^/dir1|^/dir2' | xargs -n1 /your/shell/script

should do it

read up on egrep and/or xargs in the man pages.


HTH,

p5wizard
 
Thank a lot to khalidaaa and p5wizard. Both suggestions were awesome. Great job folks
philipose
 
Thank you philipose for giving me the first star in this forum :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top