Operating System - HP-UX
1820137 Members
3235 Online
109619 Solutions
New Discussion юеВ

find command upto 2 sub-directory depth level

 
SOLVED
Go to solution
Shivkumar
Super Advisor

find command upto 2 sub-directory depth level

Hi,

What is the command syntax if i need to find the files and directories using find command upto the 2 sub-directory depth level from the specified search directory ?
Also how to include search for hidden files and sub-directories in the above command syntax ?

Thanks,
Shiv
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: find command upto 2 sub-directory depth level

Hi Shiv:

# find /mypath -xdev -print

...would find both files and directories recursively down every subdirectory. Hidden files (those with a leading ".") are also returned implicitly.

# find /mypath -xdev -type f -print

...would do the same as the first example, but return only files.

If you don't want to descend a particular subdirectory, you need to do something like:

# find /mypath -type f ! -path "/mypath/.shiv/*" -a ! -path "/mypath/.jrf/*"

...would find *files* (only) in the '/mypath' directory, but *skip* descending '/mypath/.shiv' and '/mypath/.jrf'.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: find command upto 2 sub-directory depth level

To descend upto the 2 sub-dir depth level starting from "/mydir" use:

# # find /mydir ! -path "/mydir/*/*/*"

...this will list hidden files and sub-dirs too.

~hope it helps
spex
Honored Contributor

Re: find command upto 2 sub-directory depth level

Hi Shiv,

GNU find has the '-maxdepth' directive.

# find /path -maxdepth 2 -print

Without GNU find, you will have to grep on the number of slashes or directories in the path.

GNU find is available here:
http://hpux.cs.utah.edu/hppd/hpux/Gnu/findutils-4.2.28/

PCS