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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can we limit "find" to the current directory

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
I have
A/B/ea
A/B/eb
A/B/ed
A/B/ef
A/B/eg/ea


And when i m doing
Find /A/B –type f –name "e*" i have
A/B/ea
A/B/eb
A/B/ed
A/B/ef
A/B/eg/ea (i don't want this file!!!!)

But i don't want to find search in sub-directories of A/B/
How could i do????
 
I was too fast it seems;
ls -d A/B/*e*
whould be slightly better.
 
play a litte with the -prune opt of find
see manpages
 
it is not ok:
your solution gives me:
A/B/ea
A/B/eb
A/B/ed
A/B/ef
A/B/eg
and A/B/eg is not a sample file but a directory
 
cantubas,
yes, I know.
That's why I wrote 'slightly better'.
I did not write 'correct'.
Sorry
 
sorry but i haven't got maxdepth option on HPUX
 
Perhaps -level ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I think -maxdepth is GNU find only. Try -prune, e.g...
[tt]
cd /A/B
find . \( ! -name . -prune \) –type f –name "e*" [/tt]
 
Hi:

If your find doesn't support prune or maxdepths, perhaps you can modify this. The following one-liner lists all the filenames in the current working directory only. One caveat — this method is terribly inefficient because find still forces a check of the entire directory tree structure. (For Solaris, use nawk instead of awk.)

find . -type f -print | awk ' gsub("^./","") ' |egrep -v "/"

Regards,


Ed
 
olded, a less inefficient way:
find . -type -f | grep -v '/.*/'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
no, no, phv: very efficient
mine is a little shorter
find . >/dev/null
olded: (on solaris) why not
cd /usr/bin; mv awk oawk; ln -s nawk awk
?
 
Try this:
Code:
dir=/A/B
basedir=`basename $dir`
find $dir \( -type d ! -name $basedir -prune \) -o \( -type f -name "e*" -print \)
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top