[Gllug] counting subdirectories
Tethys
tet at createservices.com
Tue Oct 14 15:32:36 UTC 2003
"stanley" writes:
>the best I have managed is
>
>alias dc="ls -1aF | grep "/" | wc -l"
>
>this work but also includes the parent and root directories in the count.
So just remove them:
alias dircount="expr $(ls -1aF | grep / | wc -l) - 2"
Note that I've avoided using "dc" as the alias name, as that conflicts
with the very useful dc calculator. Note that in real life, I'd do this
as a shell function rather than an alias, so you can pass it parameters
more easily:
dircount()
{
_count=$(ls -1aF "${1:-.}" | grep / | wc -l)
expr $_count - 2
unset _count
}
Then you can do:
leto:~% dircount
160
leto:~% dircount /etc
90
leto:~% dircount /lib
8
Tet
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list