Al Hoang

April 30, 2008

One way to clean out a gazillion files in a directory without causing the server to hang on IO

Filed under: fixes, stupid, tech, unix — hoanga @ 5:37 am

Had a case where I had some rails app that was using files for its session store and had been running like that for months. While it was a careless (and dumb) thing to run it that way, we had to do something about it since it was eating up close to 85% of the system partition. The dumb way to try to do this is below:

nice find /tmp/ -name 'ruby_sess.*' | xargs -n 100 rm -fv

However, the problem is that this causes insanity on IO which is NOT good for a running service. (Luckily this service was merely important instead of critical) So, I present to you my quick and dirty script that will clean up all those nefarious ruby sessions files that have run amok for months.

while true; do
    nice find /tmp/ -name 'ruby_sess.*' | head -n 20 | xargs rm -fv; sleep 10
done
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • Reddit
  • StumbleUpon
  • LinkedIn

Leave a Comment

You must be logged in to post a comment.

Powered by WordPress

Protected by AkismetBlog with WordPress