How to clear browser's cache and cookies from terminal

To clean the cookies from terminal you can use the following command:

rm ~/.mozilla/firefox/*.default/cookies.sqlite

To clean all the cache, you can use:

rm ~/.mozilla/firefox/*.default/*.sqlite ~/.mozilla/firefox/*default/sessionstore.js
rm -r ~/.cache/mozilla/firefox/*.default/*

But, better you can make a backup of these files if you want to restore them latter:

mkdir -p ~/.mozilla/firefox/backup ~/.cache/mozilla/firefox/backup
mv ~/.mozilla/firefox/*.default/*.sqlite  ~/.mozilla/firefox/backup
mv ~/.mozilla/firefox/*.default/sessionstore.js ~/.mozilla/firefox/backup
mv ~/.cache/mozilla/firefox/*.default/* ~/.cache/mozilla/firefox/backup

I would like to weigh in on this issue. I have set Firefox to automatically clear all cache, cookies, etc., when I quit.

Firefox menu: Edit > Preferences > Privacy

History: Select "Use Custom Settings for History"

  • All items are checked
  • Always accept all cookies, but keep until I close Firefox
  • Clear history when FF closes: Settings: Everything is checked except Delete Saved Passwords.

If I want to clear the history, etc. while Firefox is running, I simply hit Ctrl-Shift-Delete and choose what to delete.

If Firefox is NOT running, then there is no need to run the script, as the offending stuff has already been deleted. ALMOST. Turns out all of the thumbnails are still resident in ~/.cache/thumbnails/normal and ~/.cache/thumbnails/fail. For these, I wrote a little script:

#!/bin/bash
echo "shredding cache"
find ~/.cache/thumbnails -type f -name "*.png" -exec shred -f -u -z -n 1 {} \;
echo "finished shredding"

* I fire that on a cronjob, every 3 hours.

But an even simpler way is to run bleachbit. Just as fast to click bleachbit off the menu as it is to open a terminal and run a script. For me, anyway.

Good luck!