Find Out Top Directories and Files Disk Space in Linux
Find Largest Directories in Linux
To display the biggest directories in the current working directory:
1du -a | sort -n -r | head -n 5
Let us break down the command and see what says each parameter.
du command: Estimate file space usage. a : Displays all files and folders. sort command : Sort lines of text files. -n : Compare according to string numerical value. -r : Reverse the result of comparisons. head : Output the first part of files. -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).
If you want to display the largest files in KB, MB, or GB.
Run below command:
1du -hs * | sort -rh | head -5
To display the largest folders/files including the sub-directories:
1du -Sh | sort -rh | head -5
Find Large File Sizes object Only
To display the biggest file sizes only:
1find \ -type f -exec du -Sh {} + | sort -rh | head -n 5