Home FAQ How To Clear Web Browser Cache From Commandline In Linux

How To Clear Web Browser Cache From Commandline In Linux

By sk
Published: Last Updated on 14.8K views

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.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

4 comments

Himanshu chandel August 28, 2019 - 9:46 am

I want to clear my cache and cookies excluding password

Reply
sk August 28, 2019 - 11:32 am

As mentioned in the guide, the following command will only delete the cookies, not saved passwords.

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

Reply
Hu He February 4, 2020 - 2:57 pm

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

Reply
sk February 4, 2020 - 5:30 pm

Yeah, the instructions are outdated. It worked in Ubuntu 16.04. I will check them with latest Linux distributions and update the guide soon.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More