If you want to display the largest files from the current directory
du -a | sort -n -r | head -n 5
To display output from a specific directory , here I m looking for the files from /var directory
du -a /var | sort -n -r | head -n 10
To see the same output in more readable format like in GB from the current directory
du -hs * | sort -rh | head -5
some of the options thats using with the above command explained below :
du
command: Estimate file space usage.-h
: Print sizes in human readable format (e.g., 10MB).-S
: Do not include size of subdirectories.-s
: Display only a total for each argument.sort
command : sort lines of text files.-r
: Reverse the result of comparisons.head
: Output the first part of files.
Find command to find all the large size files
The below command will display top 50 largest files (>100M) on your filesystem, and also sort by the largest comes first
find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50
-xdev
just prevents from crossing the filesystems, so the command will only search in the current physical drive
Leave a Reply