Shell Tip: Counting Directories



Have you ever had need to know the number of sub-directories under your current working direcctory? The following nifty little one liner will do just that for you. Enjoy!

find -type d|wc -l 

Comments

Alain:

Two very simple scripts in my toolbox :

1: 'lsd' : to list only the directories
[lsd= ls + d (directories) ]


ls -p $* | grep /

2: 'lsds' : to list the disk usage of each of those directories
[lsds = lsd + s (summaries) ]


for d in `lsd` # lsd is described above
do
du -s "$d"
done

REM: I use it often as


lsds | sort -n

Alain

linuxphile:

Thanks for the input. I've added both your shortcuts to my script libraries.