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

Limiting the find command

Reply to Message Icon

Original Message
Name: hoogcg
Date: December 17, 2004 at 11:55:08 Pacific
Subject: Limiting the find command
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?


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: December 17, 2004 at 15:29:27 Pacific
Subject: Limiting the find command
Reply: (edit)

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?


Report Offensive Follow Up For Removal

Response Number 2
Name: Jc
Date: December 18, 2004 at 00:27:30 Pacific
Subject: Limiting the find command
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Limiting the find command

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software