Is there anyway to get the "find" command in Unix to not traverse subdirectories...

LordJezo

Banned
May 16, 2001
8,140
1
0
and only get it to search in the current directory?

As far as I know it will always traverse into subdirectories of where it is run...
 

LordJezo

Banned
May 16, 2001
8,140
1
0
I get this...

$ find -maxdepth 0 *
find: path-list predicate-list
$

What am I doing wrong?

From the man pages:

-maxdepth 0 limits the search to the command line arguments.
 

TonyRic

Golden Member
Nov 4, 1999
1,972
0
71
find 0 . filename.foo -maxdepth

What the error means is that options MUST come after all path/file information. eg, at the end of the command line
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
tppytel@timaeus:~$ rm -rf test
tppytel@timaeus:~$ mkdir test
tppytel@timaeus:~$ cd test
tppytel@timaeus:~/test$ mkdir subdir
tppytel@timaeus:~/test$ touch apple pear grape1 grape2 subdir/peach subdir/grape3
tppytel@timaeus:~/test$ ls -R
.:
apple grape1 grape2 pear subdir

./subdir:
grape3 peach
tppytel@timaeus:~/test$ find * -name "grape*" -maxdepth 0
grape1
grape2
tppytel@timaeus:~/test$


edit: Ow... too much bold...
 

LordJezo

Banned
May 16, 2001
8,140
1
0
Originally posted by: TonyRic
find 0 . filename.foo -maxdepth

What the error means is that options MUST come after all path/file information. eg, at the end of the command line

Nope, no work either...

$ find 0 * -maxdepth
find: bad option -maxdepth
find: path-list predicate-list
$



Maybe its the version of Unix I am in.. or the shell I am running... ?
 

LordJezo

Banned
May 16, 2001
8,140
1
0
Originally posted by: cleverhandle
tppytel@timaeus:~$ rm -rf test
tppytel@timaeus:~$ mkdir test
tppytel@timaeus:~$ cd test
tppytel@timaeus:~/test$ mkdir subdir
tppytel@timaeus:~/test$ touch apple pear grape1 grape2 subdir/peach subdir/grape3
tppytel@timaeus:~/test$ ls -R
.:
apple grape1 grape2 pear subdir

./subdir:
grape3 peach
tppytel@timaeus:~/test$ find * -name "grape*" -maxdepth 0
grape1
grape2
tppytel@timaeus:~/test$


edit: Ow... too much bold...

Must be the version of Unix being run here then.. it wont work for me.

"find * -name "grape*" -maxdepth 0" comes back with saying -maxdepth is a bad option

:(

oh well, thanks for trying.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
man find, /depth

If it's not in there then you are probably out of luck, or you can just use sed or something to weed out the deeper stuff (although it may be slower if there's lots of stuff there)