Unix Shell - Re: How do I find file "findme" in tree "bigtree" searching only s

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2007 > Re: How do I find file "findme" in tree "bigtree" searching only s





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: How do I find file "findme" in tree "bigtree" searching only s
Sven Mascheck

2007-08-22, 1:22 am

James Michael Fultz wrote:

> $ find bigtree -wholename '*/in_here/*' -name findme -print
> bigtree/in_here/findme


But remember "bigtree/in_here/unwanted/findme". Why not just

find bigtree -wholename '*/in_here/findme'


Chris Allen wrote:

> $ find "bigtree" ! -name "in_here" -prune
>
> Why doesn't this work?


This also applies -prune to bigtree itself and thus won't yield anything
except it.

If you work around this by adding "! -name bigtree", a deep directory
"in_here" still won't be reached because -prune already stops at the
higher level directories with other names. You can understand such
constructs by adding one expression at a time and looking at the results.

Instead of working with exclusion and negation, you should approach
straight ahead by finding the directories of interest and search
again from there. But remember that you don't want to descend
further then ("find . ! -name . -prune").

You can plug in a script for a robust way to get the full pathnames,

find bigtree -type d -name in_here -exec \
sh -c 'find "$1"/. ! -name . -prune -type f -name findme' sh {} \;

A few implementations offer expressions to simplify this a lot,
the above in contrast works on most systems.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com