Using ls to Show Directory Size – Updated & Explained
Note - I've written about this before (here). In my opinion, this is a vast improvement over that earlier version.
This title of this post is not entirely accurate. The post is actually about a script that will list files and directories in the same format as ls -l (the "long listing" format of the ls command), except it will correctly report the size of directories (and all of the files within them). Technically, it is actually in the format of ls -lhL.
This is functionally very different than the output of ls. Typically ls lists the size of directories not including their contents. This produces a very small number, which is the amount of disk space the directory's meta-data takes up (i.e. the names of files within the directory). Here is an example:
ls -lhL
total 116K drwxr-x--- 1 james users 44K 2010-04-22 17:21 movies drwxr-x--- 1 james users 48K 2010-04-03 22:22 music drwxr-x--- 1 james users 0 2009-12-11 16:20 photos drwxr-x--- 1 james users 4.0K 2009-12-13 22:36 data drwxr-x--- 1 james users 20K 2010-04-27 00:56 tv