Find largest directories one-liner

These one-line Unix-like shell commands help find the directories consuming the most hard drive space. This command lists the top 10 largest directories in the specified path. This is useful to HPC where disk quota as seen by quota -s or similar indicates it’s time to clean up some files.

du -hd1 /path/to/check 2>/dev/null | sort -rh | head

While disk size quota is often the main concern, there is often also a quota on the number of files (inodes) that can be owned by a user. To find the directories with the most files, use this command:

find /path/to/check -type f -printf '%h\n' 2>/dev/null | sort | uniq -c | sort -rn | head

Graphical terminal disk usage program “ncdu” is a widely-available Ncurses based program showing the largest files. NCDU is more user-friendly than the plain text method above. NCDU allows deleting files interactively. When using on WSL, specify the desired drive like (for C: in this example):

ncdu /mnt/c