Kevin McKelvin

Clearing old Rails logs

8 September 2012

When developing Rails apps, the logs tend to subtly grow without being checked. On one machine I freed up 10GB of disk space just by clearing old Rails development and test logs.

If you’re like me, you probably have most of your projects sitting in a Code or Projects directory in your home. You probably tail -f the log file once every now and again, but don’t really need to keep the entire log file around.

Here’s a shell command that will go through every project in the ~/Code directory and clear out old log files.

find ~/Code -type d -iname log -maxdepth 2 | xargs -I% find % -type f -iregex ".*log$" | xargs rm

I’ve got this command aliased to rmlogs in my zshrc as well.

Kevin McKelvin

These are the online musings of Kevin McKelvin. He is the CTO at Resource Guru, and lives in Newcastle upon Tyne, UK.