Created
March 4, 2012 16:40
-
-
Save docwhat/1973799 to your computer and use it in GitHub Desktop.
Script to vacuum all sqlite database on my system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
echo "Scanning for sqlite databases..." | |
find \ | |
~/Library\ | |
~/Pictures/\ | |
-type f '(' -iname '*.sqlite' -o -iname '*.db' ')' \ | |
-print0 | while read -r -d $'\0' filename; do | |
filetype=$(file "${filename}") | |
if [[ "${filetype}" =~ 'SQLite 3' ]]; then | |
oldsize=$(stat -c %s "${filename}") | |
nice sqlite3 "${filename}" vacuum | |
newsize=$(stat -c %s "${filename}") | |
if [[ $oldsize -ne $newsize ]]; then | |
change=$(( 100 - (100 * $newsize) / $oldsize )) | |
echo "${filename}: ${change}% " | |
fi | |
fi | |
done | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don’t use Thunderbird nor do I use this script anymore.
The
echo
is what prints the file name and percent change.