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.
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.