Skip to content

Instantly share code, notes, and snippets.

Last active October 29, 2018 01:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stefansundin/70400e8b6cb22f7ea7e0 to your computer and use it in GitHub Desktop.
Script that finds out the ruby versions used in subdirectories, to help you reclaim disk space.
# cd src
# wget
# chmod +x
# ./
for F in *; do
[[ ! -d "$F" ]] && continue
unset V
if [[ -n "`find "$F" -maxdepth 1 -type f -name *.gemspec`" ]]; then
# echo Skipping gem $F
elif [[ -f "$F/.ruby-version" ]]; then
V=`cat "$F/.ruby-version"`
elif [[ -f "$F/Gemfile" ]]; then
V=`cat "$F/Gemfile" | egrep "ruby [\"\'][0-9\.]+[\'\"]" | sed -e "s/ruby [\'\"]//" -e "s/[\'\"]//"`
[[ -z "$V" ]] && continue
printf "%25s: %s\n" "$F" "$V"
if [[ -d "$F/vendor/bundle" ]]; then
echo You have a vendor/bundle directory here, are you sure you need it?
echo If you remove it, remember to remove .bundle/config too!
du -hs "$F/vendor/bundle"
echo Ruby versions in ~/.rbenv/versions/:
(cd ~/.rbenv/versions/ && du -chs *)
echo To uninstall a ruby version:
echo rbenv uninstall 2.1.2
echo To clean up gems:
echo Go to one app and run:
echo 'bundle clean --force'
echo Then go to the rest and simply run: bundle
echo Logfiles larger than 10M:
find . -iname *.log -size +10M -exec du -h {} \;
echo To clear out your logs, run one of these:
echo 'for d in *; do ([[ -f "$d/Gemfile" ]] && echo "$d" && cd "$d" && bundle exec rake log:clear &> /dev/null); done'
echo 'find . -iname *.log -size +10M | xargs rm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment