How to find the biggest directories on disk
How to find the biggest directories on the disk?
Run the du command and filter the output using sort.
du -ahx / | sort -hr | headLooking to clean up some data, but unclear what the biggest directories are on the disk or within a partition? In this FAQ we look at how to quickly find them.
Find biggest directories
With the du command we can count the disk usage of directories. By using the --all option, it will combine the size of both files and underlying directories.
There is also the option --one-file-system, which will count only directories and files on the same file system. This is useful when there are external mounts. For example when using NFS, we don’t want to scan the full NAS as well.
du --all --one-file-system /
Want to use the shortened options and sort the output? Use sort to do the sorting and head to only show 10 results.
du -a -x / | sort -n -r | head
Combine the options of the commands to make them even shorter.
du -ax | sort -nr | head
Making it human-readable
The output can be a bit friendlier by using human-readable output. In that case, we need to tell both du and sort to change the default output style.
du --all --human-readable --one-file-system / | sort --human-numeric-sort --reverse | head
Want to use the shortened options for this command as well?
du -ahx / | sort -hr | head