If you want to find what files and directories are taking up space on your system, there is a very short and easy command that can be used on the command line. Keep reading if you want to learn how…
The command to find disk usage is really just du. But if we pipe it to sort, it helps when there are many items. So this is what I use:
du -sh * | sort -nr
This will list all files in your current directory path. If you want to check a specific directory, change the asterisk to something like this:
du -sh /home | sort -nr
Or the check the contents of a directory:
du -sh /home/* | sort -nr
As you can see, I’m using a couple options with the du command:
- The -s flag means –summarize. The output is just a summary of the directory listing. If this is omitted, then each file and directory in the path will be listed.
- The -h flag means –human-readable. The output will prints sizes in human readable form instead of total number of bytes.
Likewise, I’m using these options with the sort command:
- The -n flag means –numeric-sort. The output is sorted numerically.
- The -r flag means –reverse. The output is sorted in reverse order so that the largest is last.
For more information and other options of these commands, be sure to check the man pages: