Cleanup firefox's database.

pgrep -u `id -u` firefox-bin || find ~/.mozilla/firefox -name '*.sqlite'|(while read -e f; do echo 'vacuum;'|sqlite3 "$f" ; done)
Sqlite database keeps collecting cruft as time passes, which can be cleaned by the 'vacuum;' command. This command cleans up the cruft in all sqlite files relating to the user you have logged in as. This command has to be run when firefox is not running, or it will exit displaying the pid of the firefox running.

By: kamathln
2009-08-22 10:36:05

2 Alternatives + Submit Alt

What Others Think

The first part isn't strictly necessary, right? Since sqlite will fail gracefully if firefox is already running? I think you could use find to do everything, with an admittedly odd-looking -exec argument: find ~/.mozilla/firefox -name "*.sqlite" -exec bash -c "<<<'vacuum;' sqlite {}" \; using "here documents" to substitute a string for stdin. Putting echo before bash helps to see what commands would be run without running them :-).
bwoodacre · 670 weeks and 3 days ago
Yeah. I guess so. I was ujst being extra carefull with the pid part. With the "do everything with find, I do completely agree with you. And it is better too, because it will correctly handle if there is a newline in the file name. Whereas my code will fail miserably. But I would like to point out that you need to be carefull with your quotes. find ~/.mozilla/firefox -name '*.sqlite' -exec bash -c "
kamathln · 668 weeks and 3 days ago
Wow, all this seemed to do it delete my profile. -1
nbv4 · 668 weeks and 3 days ago
@nvb4 delete your profile?? wierd. That should never happen unless your sqlite files were corrupted in the first place. Did you use a wrong version of sqlite?
kamathln · 667 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: