The other day a fellow Linux user asked me how to clear Firefox browser's cache from command line. He already knew how to do it in graphical way. However, he was just curious to know how to do it from command line. For those wondering, this brief guide explains how to clear web browser cache from commandline in Linux. In this tutorial, I have included steps to clear browsing cache for both Google Chrome and Mozilla Firefox browsers.
Table of Contents
Clear Web Browser Cache From Commandline In Linux
Clear Mozilla Firefox browser cache
Usually, the browser's cache will be saved in your $HOME folder. You must backup the following files, so you can restore them back just in case if something went wrong.
First, create a backup directories.
$ mkdir -p ~/.mozilla/firefox/backup ~/.cache/mozilla/firefox/backup
Then, run the following commands one by one to backup browsing data:
$ 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
To restore the backup, just switch the source and destination locations in the above commands.
Once you backup all files, run the following command if you only want to clean the cookies:
$ rm ~/.mozilla/firefox/*.default/cookies.sqlite
If you want to to clean the whole browsing cache, then run the following command:
$ rm ~/.mozilla/firefox/*.default/*.sqlite ~/.mozilla/firefox/*default/sessionstore.js
$ rm -r ~/.cache/mozilla/firefox/*.default/*
Restart your Firefox browser. You will now see the browsing data is gone.
Clear Google Chrome browser cache
If you use Google Chrome or Chromium, backup the following files. Just in case if you want your browsing data back, you can just restore them easily.
$ mkdir -p ~/.google/chrome/backup
$ mv ~/.config/google-chrome/Default/ ~/.google/chrome/backup
$ mv ~/.cache/google-chrome ~/.google/chrome/backup
Once the backup is done, you can then clear the Chrome browser's cache by removing the following files:
$ rm ~/.config/google-chrome/Default/
$ rm ~/.cache/google-chrome
Hope this helps.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
4 comments
I want to clear my cache and cookies excluding password
As mentioned in the guide, the following command will only delete the cookies, not saved passwords.
rm ~/.mozilla/firefox/*.default/cookies.sqlite
How old are these instructions? I’m in Linux Mint 19.3 with the latest everything. And for my troubles I get:
m: cannot remove ‘/home/hu-he/.mozilla/firefox/*.default/*.sqlite’: No such file or directory
Yeah, the instructions are outdated. It worked in Ubuntu 16.04. I will check them with latest Linux distributions and update the guide soon.