Skip to content

Instantly share code, notes, and snippets.

@stefansundin
Last active October 29, 2018 01:16
Show Gist options
  • Save stefansundin/70400e8b6cb22f7ea7e0 to your computer and use it in GitHub Desktop.
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.
#!/bin/bash
# cd src
# wget https://gist.githubusercontent.com/stefansundin/70400e8b6cb22f7ea7e0/raw/ruby-versions.sh
# chmod +x ruby-versions.sh
# ./ruby-versions.sh
for F in *; do
[[ ! -d "$F" ]] && continue
unset V
if [[ -n "`find "$F" -maxdepth 1 -type f -name *.gemspec`" ]]; then
# echo Skipping gem $F
continue
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/[\'\"]//"`
fi
[[ -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"
fi
done
echo
echo Ruby versions in ~/.rbenv/versions/:
(cd ~/.rbenv/versions/ && du -chs *)
echo
echo To uninstall a ruby version:
echo rbenv uninstall 2.1.2
echo
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
echo Logfiles larger than 10M:
find . -iname *.log -size +10M -exec du -h {} \;
echo
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