du command on Linux (Disk Usage)
The du command in Linux (disk usage) will provide a detailed list of disk usage.
It is very useful for determining where the available disk space went, so you can investigate which directory is consuming the disk.
If we don’t pass a directory as a parameter, it uses the current directory as a search base.
The most common options are:
- -a: Shows all files and not just directories;
- -c: Shows a total at the bottom of the list;
- -h: Shows information in a simpler way. Uses the letters M for megabytes and G for gigabytes;
- -s: Shows a summary of the specified directory and not the total of each subdirectory;
- -S: Excludes subdirectories from the count;
Examples:
With the -sh option, it shows the totalizer, including the subdirectories:
With the -Sh option, it shows the totalizer, excluding subdirectories:
If you want to know the total of each subdirectory:
The —inodes option shows the inode count:
You can investigate the entire disk, from the root/:
Note that pseudo-file systems such as /proc, /dev, and /sys do not take up disk space because they are actually abstractions of the Kernel and subsystems.