Pages

Friday, November 1, 2013

Find largest files

Type the following command at the shell prompt to find out top 10 largest file/directories:
# du -a /var | sort -n -r | head -n 10

If you want more human readable output try:
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10

Where,
  • du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
  • du command -s option : show only a total for each argument (summary).
  • du command -x option : skip directories on different file systems.
  • sort command -r option : reverse the result of comparisons.
  • sort command -h option : compare human readable numbers. This is GNU sort specific option only.
  • head command -10 OR -n 10 option : show the first 10 lines.
The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):
 
for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11
 

This is also a good one ... here this returns the top 40:
find  -type f -printf '%s %p\n'| sort -nr | head -40



also see: http://linuxcountry.blogspot.com/2013/05/find-and-sort-all-files-by-size-save.html

No comments:

Post a Comment