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 the files. -5 Show 5 Directory result
- -n: Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).
using du
with human-readable sizes and a maximum depth of 1 directory level is as follows:
du -h --max-depth=1
This command will display the sizes of the directories in the current location with human-readable sizes and limit the display to a maximum depth of 1 directory level.
display the largest files in KB, MB, or GB.
du -hs * | sort -rh | head -5
To display the largest folders/files including the sub-directories, run
du -Sh | sort -rh | head -5
Find Out Top File Sizes Only
If you want to display the biggest file sizes only, then run the following command
find -type f -exec du -Sh {} + | sort -rh | head -n 5
find /home/downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5 Or find /home/downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5