Linux: Get size of sub-directores in current directory

Tags: linux shell tool

Edit: Now that I'm more familiar with the Linux command line, I realize that I was trying to reinvent the wheel. I don't know if I missed this part of the du manpage or what, but the functionality I was looking for is baked in:

du -hd 1

The h flag is for "human-readable format", and d 1 tells the program to go "no deeper than 1 level from the given folder". (With no folder specified, the current directory is used.)


The following string of commands can be used to not only list the immediate sub-directories of the current directory, but also print their size in human-readable format (kilobytes):

du -sh `ls -l | grep '^d' | awk '{print $9}'`

Here's how it works:

Put them all together, and they work like a well-oiled machine to produce a new, specific utility. The utility can become a part of your regular Linux command-line arsenal by creating a text file out of it and flagging it as executable.


Update: EspadaV8 posted a wonderful suggestion for trimming the fat from this command by avoiding the use of awk and piping altogether. Give it a try yourself:

du -sh `ls -d */`