Non recursive find command

Hi,

I have question is related to find command. I want to find command should search in current folder only not recursive mode(sub-folders).

I found a one way of,
find . \( -name success -prune \) -o -name "Rajini*"

How ever, my current folder is having lots sub-folders and am not interested to give all sub-folders names with find command.

Waiting for your valuable reply.

Thanks,
Naga :cool:

If you don't want recursion, is find even the right command?

echo Rajini*

Some versions of find have a -maxdepth option which allow you to control how deep into subdirectories it will recurse. With -maxdepth 1 it will only search the current directory.

Thanks for your reply.

As you know, simple find by default recrusive option is true. As you quoted, i tried -maxdepth, how ever it's not working with my OS.

PFB details, (am using SunOS 5.9)

> find . -name "Rajini*" -maxdepth 1
find: bad option -maxdepth
find: path-list predicate-list

Is there any other apart from -maxdepth?

Waiting for your valuable reply

Thanks,
Naga :cool:

You can feed the output of find to grep, but that won't prevent it from going recursive, just remove the subdirectories from the output (which is a problem if you want to avoid the overhead of recursive processing, but perhaps acceptable if that's not the problem you are trying to solve).

I'm still thinking you should not be using find in the first place, though.

Thanks.

-Naga :cool:

I concur with era...the echo command is ideal for your scenario and from your post it seems that you have a find one-liner.

find /folder/* -prune -type f -name 'Rajini*'

This works for me on a Solaris system

1 Like

run it from success dir
i mean cd ~/success

find ../success \( ! -name success -prune \) -o -name "Rajini*"