Computing.Net > Forums > Unix > Limiting the find command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Limiting the find command

Reply to Message Icon

Name: hoogcg
Date: December 17, 2004 at 11:55:08 Pacific
OS: HP-UX
CPU/Ram: Not relevent
Comment:

Is there a way to limit the find command from searching in subdirectories below the directory the search is started in?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 17, 2004 at 15:29:27 Pacific
Reply:

Hi:

The GNU find command has a maxdepth option which controls how many directory levels to search.

If you don't have it, you can use find's -prune option to search only the top directory:

find . \( -type d ! -name . -prune \) -o \( -type f -print \) | awk ' gsub("^./","") '

If you are going to look only at the top directory, have you considered using ls -la with some sort of script?


0

Response Number 2
Name: Jc
Date: December 18, 2004 at 00:27:30 Pacific
Reply:

Refer the options -maxdepth and -mindepth of find command

man find


-maxdepth levels
Descend at most levels (a non-negative integer)
levels of directories below the command line arguĀ­
ments. `-maxdepth 0' means only apply the tests
and actions to the command line arguments.

-mindepth levels
Do not apply any tests or actions at levels less
than levels (a non-negative integer). `-mindepth
1' means process all files except the command line
arguments.


Jc


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Limiting the find command

Clean up the / fs with find command www.computing.net/answers/unix/clean-up-the-fs-with-find-command/1417.html

find command - korn shell www.computing.net/answers/unix/find-command-korn-shell/5568.html

find command www.computing.net/answers/unix/find-command/6108.html