The Linux disk usage command "du" is a handy command used to check information about the disk usage of files and directories on the server. The command has many flags you can use to expand the result or change its format, making it more readable in the process. When used alone without any options it will provide a list of the directories and their size recursively.
Here is an example of the command used by itself:
[user@hostname]# du /home/user 50 /home/user/downloads 4 /home/user/.chrome/plugins 4 /home/user/.chrome/extensions 11 /home/user/.chrome 11 /home/user/.ssh 781000 /home/user/Ubuntu-16.10 781080 /home/user
By default, the information about the disk utilization will be provided in bytes. We will give you a couple of useful examples of this command that will make the output a lot more understandable.
Here is an example of this command when used with the "-h" flag which stands for "Human Readable". It will convert the output into MegaBytes:
[user@hostname]# du -h /home/user 50K /home/user/downloads
4.0K /home/user/.chrome/plugins
4.0K /home/user/.chrome/extensions
11K /home/user/.chrome
11K /home/user/.ssh
763M /home/user/Ubuntu-16.10
763M /home/user
Instead of having this command show a list of all the directories and their size, and make it show the total disk space inside the folder, you can use the "-s" option which stands for "Summary":
[user@hostname]# du -sh /home/user 763M /home/user
We recommend combining the above command with it the "-h" flag to generate the output in a human-readable format. The flag we are gonna discuss in this tutorial is the "-a" flag, which stands for "All".
[user@hostname]# du -ah /home/user 4.0K /home/user/.bash_logout 50M /home/user/downloads/Joomla_3.9.16-Stable-Full_Package.tgz 350K /home/user/downloads/MagentoOpenSource2.3.4.zip 40K /home/user/downloads 25M /home/user/wordpress-5.3.2.zip 4.0K /home/user/.chrome/plugins 4.0K /home/user/.chrome/extensions 12K /home/user/.chrome 4.0K /home/user/.bashrc 763M /home/user/Ubuntu-16.10/ubuntu-16.10-server-i386.iso 763M /home/user/Ubuntu-16.10 1214M /home/user
The "-a" flag will display the size of all the directories and files regardless of their extension and format. Again, we recommend combining it with the "-h" option to make the output cleaner.