Operating System - HP-UX
1838243 Members
3538 Online
110125 Solutions
New Discussion

Re: How to find directories in depth

 
sreeram n
Frequent Advisor

How to find directories in depth

Hi Admins.

I am looking for the options of find command to find out the directories in depth. Some thing like 2 level or 3 level. This should display the dir names with permissions.

Could anyone can help on this.
Thanks
Sree
Sreeram N
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: How to find directories in depth

Try something like this:

find /startdir -type d -exec "ll -d" {} \;


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: How to find directories in depth

Hi Sree:

If you are looking to limit 'find's ouput or selection to a particular depth (number of nodes) then you need to look either at the GNU utilities or roll-your-own. With Perl, this is easy. Here's a quick script to do your bidding.

# cat ./finddir
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
my $maxdepth = 3;
my ( $dir, $mode, $n );
find(
sub {
if ( -d ( $dir = $File::Find::name ) ) {
$n = $dir =~ tr ,/,/,;
$mode = ( stat($dir) )[2];
printf( "%04o %-s\n", $mode & 07777, $dir ) if $n <= $maxdepth;
}
},
@ARGV
);

...adjust the value of '$maxdepth' to your taste. Run the script passing the directory or directories you want to examine, like:

# ./finddir /var

Regards!

...JRF...
Scot Bean
Honored Contributor

Re: How to find directories in depth

How about 'll -Rd *'
sreeram n
Frequent Advisor

Re: How to find directories in depth

James,
Thanks for your quick reply. While running the scrips I am getting the below error.
./find_dir.pl[3]: use: not found
./find_dir.pl[4]: use: not found
./find_dir.pl[5]: use: not found
./find_dir.pl[6]: my: not found
./find_dir.pl[6]: syntax error at line 7 : `(' unexpected

I am not good in scripting so if you can help me to sort out this it will be highly appreciable
Sreeram N