How to see disk usage using the Linux command line

Description

Disk usage on subdirectories on Linux are not entirely easy to see and you have to use the du command to see how much space is being used further down. One caveat with du is that it can take really long on large file systems if run close to the root directory. So be careful!

The typical du command to see disk usage on a Linux machine is the following:

du -h --max-depth=1

-h means human readable format and the max-depth parameter will show values one level deep.

You could also just do du --summarize to see a summary.

But what do you do when you want this sorted?

How to output disk usage sorted by size

Use the following command to sort disk usage by size in the current directory:

sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null

Note: This command can take very long on a large server. On a 800 GB server with an SSD array it took around 10 minutes before output was produced.

Reference

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top