Save disk space by truncating dev log files
The problem
Ever wonder where all that disk space is going?
Over the course of a year we touch alot of projects here at Velocity Labs. It's not uncommon for one of us to touch 5+ different code bases in that time.
When we're actively working on a project we're running it in development mode, running test specs, etc. All that contributes to dev and test log files growing larger and larger. Then we move on to the next project and forget about those files.
2 gigs!?
Is there a quick way to clean these up?
The solution
Well there happens to be a truncate unix command we could use to shorten up these log files. The only problem is that truncate isn't available on OSX.
But we can get the same functionality via Homebrew + coreutils.
==> Installing coreutils ==> Downloading https://homebrew.bintray.com/bottles/coreutils-8.29.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring coreutils-8.29.high_sierra.bottle.tar.gz ==> Caveats All commands have been installed with the prefix 'g'. If you really need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc like: PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" Additionally, you can access their man pages with normal names if you add the "gnuman" directory to your MANPATH from your bashrc as well: MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH" ==> Summary 🍺 /usr/local/Cellar/coreutils/8.29: 430 files, 8.9MB
Now we can find log files and pass them to truncate setting them to 0 in size.
One thing of note is that all coreutils commands are prefixed with a 'g', so we'll be using gtruncate
The -s flag of gtruncate allows us to set the file to any size after truncation.
So let's check one of our logs and see what size it's at now.
Oh yeah, nice and empty, go forth and reclaim that space from your dev machines!
Need help with your project?
We specialize in Ruby on Rails and JavaScript projects. Code audits, maintenance and feature development on existing apps, or new application development. We've got you covered.