The df and du commands are useful tools for checking disk space in Linux, but they have some key differences. The df command stands for disk free, and it shows the amount of space taken up by different drives or filesystems. The du command stands for disk usage, and it shows the amount of space used by files or directories and their subdirectories.
The df command gives a quick overview of the entire filesystem, including the size, used space, available space, usage percentage, and mount point of each drive. The command gives a detailed report of the space used by a specific file or directory and its subdirectories and shows the size of each file or subdirectory within a given directory.
The df command is useful when you want to see how much space is left on your drives or filesystems, or when you want to compare the size and usage of different drives or filesystems. The command is useful when you want to see how much space a file or directory takes up, or when you want to find out which files or directories are taking up the most space.
Using the du and df Commands
Review the three commands below which are very useful for determining space usage in the server and directories.
Using df -h we can view the usage and remaining space of our server, as shown below.
Using du -sh /home, we can view the size of the home directory. The “/home” can be changed to whichever directory you’d wish to examine.
To view the list of largest files in a directory and have it sorted by file size, the command below can be used.
*Note: both “/home” can be changed to any directory and “50” to whichever value of results you’d like to receive.
du -ahx /home | sort -rh | head -50