How to clear the browser cache from the command line

Clear browser cache from Terminal

There are many people, especially Windows users (and some macOS users), who think that Linux users like to complicate our lives. In fact, I have read comments from people who label us "freaks out who just want to hesitate" or something like that. Nothing is further from reality. These people think that way because they believe that EVERYTHING is done from the terminal ... Sure, they have never touched Linux ... The Terminal is used, but sometimes it serves to save time or perform more complex tasks such as clear browser cache.

It is clear that any browser allows you to delete the cache from some part of its options, but this article is aimed a little at those who feel comfortable with Terminal or to those who want to save these commands in a script to launch from the dock or any shortcut. In this post we will talk about how to do it for Firefox, the browser that is included by default in most Linux distributions, and Google Chrome, another of the most used options for being the best for some tasks.

Clear Firefox cache

Before doing this, it is worth making a backup of everything. For this we will write these commands one by one:

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

If we want to restore the files we will change the order of the directories.

To delete the browser cache from the Terminal we will write the following:

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

From the above, "rm" means "remove", "-r" will say to remove directories and their content and the rest are paths. We remember that "~ /" refers to our personal directory. Once the commands have been entered, we restart the navigator.

NOTE: : the theory says that the asterisks that I have added behind the ".default" directories should not be there, but I have added them because in my case it told me that it was not there. The asterisks mean "all" those who comply with something. By adding one in front (*.) And one behind, we are telling it everything that the word "default" contains regardless of whether it has something in front or behind.

How to do it in Chrome

As in Firefox, we will first make the backup copies of the Chrome files. We will use the following commands, one by one:

mkdir -p ~/.google/chrome/backup
mv ~/.config/google-chrome/Default/ ~/.google/chrome/backup
mv ~/.cache/google-chrome ~/.google/chrome/backup

As in Firefox, to restore the copies we will change the order of the directories.

To delete the Chrome cache we will use these commands:

rm ~/.config/google-chrome/Default/
rm ~/.cache/google-chrome

Bonus

Well. We already know how to delete the Firefox and Chrome cache from the Terminal, but is it worth it? From my point of view I would say yes and no. You are reading a user who does not like having to make several clicks to shut down or restart the computer. So much so that a long time ago I created some .desktop files to add the "poweroff" and "reboot" commands to the Ubuntu dock. And it is that, for me, if what we want is that the elimination of the cache of our browser is efficient, the best thing is to create a .desktop file that we can add to the different bars and docks available on Linux.

This is something I have to resize JPG images to 830px wide, as long as those images are on my desktop. To make sure it works we will have to create two files- A text file that contains all the lines and a .desktop file that executes the first file. In addition, we will also make sure that we can put the .desktop in practically any bar or dock. For this we will do the following:

  1. We open a text editor.
  2. We copy and paste the commands to delete the cache, each one on one line. Alternatively, they can be put on the same line by adding "&&" without the quotes.
  3. We save the file.
  4. We right click on it and check the box "it is executable" or whatever it puts in the Linux distribution that we are using.
  5. Next we are going to create the .desktop file, for which we create another text file with the following:

[Desktop Entry]
Type = Application
Terminal = false
Name = cache
Icon = / home / pablinux / Images / cache.png
Exec = PATH TO FILE
GenericName [es_ES] = Delete cache

  1. From the above we can put the name (Name) that we want, in "Icon" we put the path to the icon that we want to have the direct access, in "Exec" we put the path to the other text file and in "GenericName" we put a comment to the taste of the consumer.
  2. The next thing is to put the shortcut or .desktop in a well accessible place, such as a bar (in MATE or Plasma, for example) or a dock (as in Ubuntu). In the case of highly customizable graphical environments such as KDE or MATE, we can drag the .desktop wherever we want, but this is not the case in other operating systems. In other operating systems we have to put the .desktop in the path of the shortcuts of the rest of the applications, as is usr / share / applications in Ubuntu and derivatives. By putting a shortcut there it will detect it as an application and we can add it to favorites.

What do you think is better: use the method described in this post or take a walk through the browser settings and delete the cache manually?


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.