deeejay

Bash - Find the largest files or directories

Mar 29th, 2016 (edited)
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.14 KB | None | 0 0
  1. Source: http://superuser.com/questions/9847/linux-utility-for-finding-the-largest-files-directories
  2.  
  3. To find the largest 10 files (linux/bash):
  4. find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
  5.  
  6. To find the largest 10 directories:
  7. find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
  8.  
  9. To find  the largest 10 directories (centos)
  10. du -a /var | sort -n -r | head -n 10
  11.  
  12. Human-readable format
  13. cd /path/to/some/where
  14. du -hsx * | sort -rh | head -10
  15.  
  16. From Mohan
  17. du -h . --max-depth=2 | sort -hr | sed -e 's/$/|/g'
  18.  
  19. Find top 5 largest log files
  20.  
  21. du -ha /var/log/* | sort -rh | head -n 5
  22. -h = Print sizes in human readable format (e.g., 10MB)
  23. -a = Displays all files and folders
  24. -S = Do not include size of subdirectories
  25. -s = Display only a total for each argument
  26. -c = Displays total amount of space used
  27. -k = Displays the file size in kilobytes
  28. -m = Displays the file size in megabytes
  29.  
  30. sort = sort lines of text files
  31. -n = Compare according to string numerical value
  32. -r = Reverse the result of comparisons
  33. -h = Compare human readable numbers (e.g., 2K, 1G)
Advertisement
Add Comment
Please, Sign In to add comment