list of Dirs

list of Dirs

Post by teste » Thu, 22 Jun 2006 04:14:07



Hi Gurus,
I need to have ouput of list of all the directories and sub-dir in a
folder with total no. of dirs.

find . -type d -exec wc -l ls {} \;

Any help is greatly appreciated.
Regards

 
 
 

list of Dirs

Post by Uli Wachowit » Thu, 22 Jun 2006 04:42:37



Quote:> folder with total no. of dirs.
> find . -type d -exec wc -l ls {} \;

almost ;-)

Quote:> find . -type d | wc -l

Uli

--
Tashi Delek!
Wishing you the auspicious blessings of Buddha nature, shining and
resplendent, complete fulfillment in the highest happiness!

 
 
 

list of Dirs

Post by GROG » Thu, 22 Jun 2006 05:26:59



Quote:>Hi Gurus, I need to have ouput of list of all the directories and
>sub-dir in a folder with total no. of dirs.

>find . -type d -exec wc -l ls {} \;

Assuming you need to have a list of all the directories _as well as_
the total, then (all in one line in case this wraps):

$ find . -type d | (typeset -i I=0; while read L; do I=$((I+1)); echo
    $L; done; echo Total $I dirs)

This also assumes you're using a modern bourne shell that interprets
the addition properly (ksh, bash, etc)

--
GROG! \|||/        "My life is a soap opera, but who has the

/--ooO-(_)-Ooo--\  
EMAIL: uber [dot] grog [at] gmail [dot] com

 
 
 

list of Dirs

Post by Stephane CHAZELA » Thu, 22 Jun 2006 05:59:34


2006-06-20, 12:14(-07), tester:
Quote:> Hi Gurus,
> I need to have ouput of list of all the directories and sub-dir in a
> folder with total no. of dirs.

> find . -type d -exec wc -l ls {} \;

[...]

Assumming file paths don't contain newline characters:

find . -depth -type d -print | awk -F/ '
  {
    l = ""
    for (i = 1; i < NF; i++) {
      l = l "/" $i
      n[l]++
    }
  }
  {
    print "there are/is " n["/"$0]+0 " dir(s) under " $0
  }'

--
Stphane

 
 
 

list of Dirs

Post by puzzlecracke » Thu, 22 Jun 2006 07:34:37



> 2006-06-20, 12:14(-07), tester:
> > Hi Gurus,
> > I need to have ouput of list of all the directories and sub-dir in a
> > folder with total no. of dirs.

> > find . -type d -exec wc -l ls {} \;
> [...]

> Assumming file paths don't contain newline characters:

> find . -depth -type d -print | awk -F/ '
>   {
>     l = ""
>     for (i = 1; i < NF; i++) {
>       l = l "/" $i
>       n[l]++
>     }
>   }
>   {
>     print "there are/is " n["/"$0]+0 " dir(s) under " $0
>   }'

> --
> Stphane

Why make things complicated: just use find . -type d | wc -l  as
suggested above... other posts adds unnecessary complexity.... or am I
missing something?
 
 
 

list of Dirs

Post by Michael Heimin » Thu, 22 Jun 2006 08:07:32




>> 2006-06-20, 12:14(-07), tester:
>> > Hi Gurus,
>> > I need to have ouput of list of all the directories and sub-dir in a
>> > folder with total no. of dirs.

>> > find . -type d -exec wc -l ls {} \;
>> [...]

>> Assumming file paths don't contain newline characters:

>> find . -depth -type d -print | awk -F/ '
>>   {
>>     l = ""
>>     for (i = 1; i < NF; i++) {
>>       l = l "/" $i
>>       n[l]++
>>     }
>>   }
>>   {
>>     print "there are/is " n["/"$0]+0 " dir(s) under " $0
>>   }'

>> --
>> St?phane
> Why make things complicated: just use find . -type d | wc -l  as
> suggested above... other posts adds unnecessary complexity.... or am I
> missing something?

The OP?

Added a switch to Stephane's script:

#!/bin/bash
depth="${1}"

case $depth in
        [0-9]*)
        find . -depth -type d -print | awk -v d=$depth -F/ '
        BEGIN {
                FS="/"
                }
        {
        l = ""
        for (i = 1; i < NF; i++) {
        l = l "/" $i
        n[l]++
        }
        }
        n["/"$0]+0>=d {
        print n["/"$0]+0 " dir(s) under " $0
        }'
        ;;
        *)
        echo "Usage, $0 <n> (dirlevel to show >=0)"
esac

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)

#bofh excuse 332: suboptimal routing experience

 
 
 

list of Dirs

Post by Stephane Chazela » Thu, 22 Jun 2006 15:50:51


[...]

Quote:> case $depth in
>         [0-9]*)

Should be:

case $depth in
  "" | *[!0-9]*) usage;;
  *)...

[0-9]* means anything that starts with a decimal digit.

Quote:>         find . -depth -type d -print | awk -v d=$depth -F/ '
>         BEGIN {
>                 FS="/"
>                 }
>         {
>         l = ""
>         for (i = 1; i < NF; i++) {
>         l = l "/" $i
>         n[l]++
>         }
>         }
>         n["/"$0]+0>=d {
>         print n["/"$0]+0 " dir(s) under " $0

I don't follow, what is this supposed to do? My solution was
giving the number of subdirectories for every directory (that's
what I understood the OP wanted), yours seem to do the same
unless that number of directories is greated than the argument,
I can't see why you call it "depth".

Quote:>         }'
>         ;;
>         *)
>         echo "Usage, $0 <n> (dirlevel to show >=0)"
> esac

--
Stephane
 
 
 

list of Dirs

Post by Michael Heimin » Thu, 22 Jun 2006 17:55:34




> [...]
>> case $depth in
>>         [0-9]*)
> Should be:
> case $depth in
>  "" | *[!0-9]*) usage;;
>  *)...
> [0-9]* means anything that starts with a decimal digit.

Yep, that would be more clean!

Quote:>>         find . -depth -type d -print | awk -v d=$depth -F/ '
>>         BEGIN {
>>                 FS="/"
>>                 }
>>         {
>>         l = ""
>>         for (i = 1; i < NF; i++) {
>>         l = l "/" $i
>>         n[l]++
>>         }
>>         }
>>         n["/"$0]+0>=d {
>>         print n["/"$0]+0 " dir(s) under " $0
> I don't follow, what is this supposed to do? My solution was
> giving the number of subdirectories for every directory (that's
> what I understood the OP wanted), yours seem to do the same
> unless that number of directories is greated than the argument,
> I can't see why you call it "depth".

That would just show dirs with more or equal level of dirs below
$depth, "0" would show all, as without it.

Found your script useful but thought it would be nice to be able
to only show dirs which have a specified number of dirs below.

Regards

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)

#bofh excuse 1: clock speed

 
 
 

list of Dirs

Post by teste » Fri, 23 Jun 2006 04:34:30


Quote:> almost ;-)

> > find . -type d | wc -l

> Uli

> --

Thanks Tashi... That worked for me. Thanks a lot