Quick Tip to Clean Up Rails Logs
Every few months I use this command to empty each and every one of my test.log
and development.log
files in the src
folder of my laptop:
find ~/src \
-maxdepth 6 \
-type f \
-mindepth 1 \
\( -name "test.log" -or -name "development.log" \) \
-exec truncate -s 0 {} \;
It works by…
- Finding files that match the name
- Using the
truncate
command to reduce the size of the file to 0 bytes
Instead of typing it out each time, I’ve created a quick alias in my .bash_profile
when my shell loads:
alias truncate_devlogs='find . -maxdepth 6 -type f -mindepth 1 \( -name "test.log" -or -name "development.log" \) -exec truncate -s 0 {} \;'
Then when I remember to do so, or I wrap up work on a project, a quick truncate_devlogs
recoups disk space and makes me feel better.