In this linux example, we will list top 5 largest directories in a folder. We will use linux du command to list.
How to get top 5 largest directories in a folder?
Here is an example:
sudo du -h /var/ | sort -rh | head -5
/var/ is the folder we will statistics.
head -5 means we will list top 5 larget.
Run this command, we may get a list as follows:
85G /var/ 77G /var/lib 75G /var/lib/libvirt/images 75G /var/lib/libvirt 5.0G /var/cache/pacman/pkg
From this example, we can find: to list top 5 largest directories in a folder, we can do like this:
sudo du -h folder_path | sort -rh | head -5