How to Simply Display Directory Disk Usage?

On a Unix or Linux server, the “du” command provides a quick and easy method for finding out how much space each directory is using, as well as a summary of total disk usage. For example, if you just typed “du” from the command line, the output might look like this:

624 dir211

28 dir212

28 dir213

24 dir214

28 dir215

44 dir216

156 dir217

768 dir218

4552 dir219

210776 .

This shows you disk usage for directories, but it shows output in bytes. If you want a simplified output (i.e. 1M, 2G), use the “-h” option. Type “du -h” and the output will look like this:

1.2M dir234

688K dir172

3.8M dir0283

16M dir1823

73M dir8739

8.5M dir1728

7.6M dir7382

114M dir1738

As you can see, they display simplified output, but it is not sorted. If you want to sort it by size, you will have to get a little more creative. The following command will display a simplified output sorted by size:

du -hs * | sort -h

3.3M SmallestDirectory

15M SmallerDirectory

43M SmallDirectory

48M BigDirectory

120M BiggerDirectory

458M BiggestDirectory

As you can see, du is a versatile tool that you can use to find out just how much disk space you are using overall even more specific details about individual directories and their disk usage.











Comments: