Disk Usage
How to find disk usage on the Linux machine using du utility. To get more information on du, read this manual.
To begin, open a command prompt and issue a du command, like so:
$ du
The output that you got out of it is probably not very useful. Let’s make it more human readable with -h option. And if you are only interested in summary, add -s option. This is an example of the command and it’s output, on my workstation:
$ du -hs 9.7G .
This simply shows that my current directory is using 9.7 Gigabytes of space. This is useful but let’s make this better. Let’s sort the output according to the usage on the disk. For this you will need to use sort command. Manual for this command you can find here. Try with the sort command this time, if you would like to see items with most disk usage at the top, use -r option for sort.
$ du -h | sort -hr
Now this shows a nice, sorted, human readable output. Keep reading for a more advanced examples!
Bonus
To show sub-folders no more than two levels down use -d, –max-depth=N option.
du -h --max-depth=2 *
And the final useful example is to show only top 5 entries of the output. I will also include sorting with the largest size on the top.
du -h * | sort -hr |head -5
I hope you found this useful. Enjoy!