Limit the depth of search using find

Contributor Icon Contributed by qmchenry Date Icon September 4, 2003  
Tag Icon Tagged: UNIX

The find command searches all subdirectories under the specified path by default. Using the maxdepth option, the search depth can be limited.


To run a find command limited to only the current directory and not search through any subdirectories, use the -maxdepth 0 option:

find . -maxdepth 0 -print

To search one level of directories below /usr, use:

find /usr -maxdepth 1 -print

The maxdepth option can be used in conjunction with other find options such as -name, -nouser, -atime, etc.

Previous recipe | Next recipe |
 

 
close Reblog this comment
blog comments powered by Disqus