LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   easy one (https://www.linuxquestions.org/questions/linux-newbie-8/easy-one-384037/)

shukla_chanchal 11-17-2005 12:07 PM

easy one
 
how can i count the number of directory in a directory

ls -d is not working
tell me if anyone of u know
thanks

camorri 11-17-2005 12:45 PM

Try the 'tree' command. You may need to install it first, it is not installed by default on all distros.

It will count directories and files.

Tinkster 11-17-2005 02:44 PM

Re: easy one
 
Quote:

Originally posted by shukla_chanchal
how can i count the number of directory in a directory

ls -d is not working
tell me if anyone of u know
thanks

As always in Linux/Unix there's more than one way ...

ls -l | grep "^d" |wc -l
echo "$((`find -type d -maxdepth 1|wc -l` - 1))"

Cheers,
Tink

alienDog 11-18-2005 07:10 AM

ls -1d [dirname]/* | wc -l

this won't recurse though...

Tinkster 11-18-2005 01:55 PM

Quote:

Originally posted by alienDog
ls -1d [dirname]/* | wc -l

this won't recurse though...

Plus it will count any ordinary file as well ...


Cheers,
Tink

alienDog 11-19-2005 08:43 AM

Right you are, so it seems. I should have tested it first ;)

shukla_chanchal 11-19-2005 10:16 AM

thanks u people have given me exat answer


All times are GMT -5. The time now is 07:01 PM.