How to see disk usage using the Linux command line


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

Warning: This command is a mess on a big server, it takes very long and if you have a slow disk the entire machine will have performance problems. rather do du without the -h and copy/paste into a Google Sheet and sort that way.

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



Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top