O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

'nother disk hog method
This is a little longer, but produces a sorted list in "human readable" format.

Contributed by:
[01/24/06 | Discuss (0) | Link to this hack]

Using find gives you the most flexibility in file or directory searches.

Lets say you run a virtual hosting server, and want to find mail files larger than 500k, you could do this:

  • find /home/virtual/site*/fst/var/spool/mail/* -size +500k -type f -exec du -s {} \; | sort -n | awk '{print "du -hs "$2}' > /tmp/du.cmd && bash /tmp/du.cmd
If you didn't want to use find's size feature, you can have awk do some prefiltering:
  • find /home/virtual/site*/fst/var/spool/mail/* -type f -exec du -s {} \; | sort -n | awk '$1 >= 500 {print "du -hs "$2}' > /tmp/du.cmd && bash /tmp/du.cmd
The same method works for directories:
  • find /home/*/mail -type d -exec du -s {} \; | sort -n | awk '{print "du -hs "$2}' > /tmp/du.cmd && bash /tmp/du.cmd
  • find /var/www/html -type d -exec du -s {} \; | sort -n | awk '{print "du -hs "$2}' > /tmp/du.cmd && bash /tmp/du.cmd

Is it long? Yes. Is it versitile? I think so.

O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.