If you’ve been using Vagrant to build dev environments on your laptop, it’s possible that you may have forgotten about many a few of your environments. Such was the case with my laptop as my 256 GB drive started screaming for mercy. I have quite a few project folders, and I didn’t want to perform vagrant status one-by-one. How could I quickly clean up stale environments?!?
Yes, I am aware that there are visual tools available like Vagrant Manager that could potentially have helped, but OS X already warned me that I was out of space, and I didn’t want to tempt fate by installing anything else. So, I relied on the Linux du command to help me out. I modified the instructions shared in a blog post by Moncef Belyamani and ran the following command from the prompt:
du -g * | awk '$1 > 2' | sort -nr > ~/output.txt
The du option displays storage in Gigabytes, and the sort command will display the results in order of storage usage. I was amazed by the number of projects that I had forgotten about. When all was said and done, I had reclaimed over 30 GB.
Do you have any tips for keeping track of your Vagrant storage usage? If so, share them in the comments section below.