How to clean Ubuntu safely


Back to the home page


First of all: never use cleaning applications like BleachBit! Those software wrecking balls are very risky and may damage your system beyond repair. There are a few safe cleaning actions, which I'll describe below.

Ubuntu doesn't get polluted much over time (with one notable exception, namely old kernels. More about that later). It even doesn't need defragmentation. The only cleansing actions you might want to do in Ubuntu, are the following:

Clear the updates cache

1. Use the application Software (the paper shopping bag icon in the desktop bar) to install Synaptic Package Manager.

Then click on the grey Ubuntu logo (Dash home). Query: synaptic.
Click on Synaptic Package Manager

Settings - Preferences - Files

Put the dot at: Delete downloaded packages after installation

Press the button: Delete cached package files

Clear the thumbnail cache

2. For each shown picture, Ubuntu automatically creates a thumbnail, for viewing in the file manager. It stores those thumbnails in a hidden directory in your user account (names of hidden directories and hidden files start with a dot, like .cache or .bash_history. The dot makes them hidden).

Over time, the number of thumbnails can increase dramatically. Moreover, the thumbnail cache will eventually contain many superfluous thumbnails of pictures that don't exist anymore.

My advice is therefore, to clear the thumbnail cache every six months or so. The quickest way is to use the terminal:

Launch a terminal window.
(You can launch a terminal window like this: *Click*)

Type (use copy/paste to avoid errors):

rm -v -f ~/.cache/thumbnails/*/*.png ~/.thumbnails/*/*.png

Press Enter.

Followed by:

rm -v -f ~/.cache/thumbnails/*/*/*.png ~/.thumbnails/*/*/*.png

Press Enter.

Note: this will probably affect the thumbnails on your desktop as well; in that case it should suffice to simply refresh your desktop (or log out and in again), which will create them anew.

Repeat the above in each user account.

You can permanently limit the size of the thumbnail cache as follows:

Note: for this, you have to install the package dconf-tools first.

Launch a terminal window.
(You can launch a terminal window like this: *Click*)

Type:
dconf-editor

Press Enter

In dconf-editor, click on the small triangle to expand a category. Like this, click your way to:
org - gnome - desktop - thumbnail_cache
.... and set the maximum-age to 90 (press Enter) and the maximum-size to 64 (press Enter again).

Close dconf-editor.

Repeat this in each user account. Afterwards, you won't have to pay attention to the disk space of the thumbnails anymore.

Want to get rid of polluted settings in your web browser?

3. Do you have polluted settings in Firefox, Chrome or Chromium (sometimes caused by rotten, shady or rogue add-ons), and do you wish to start anew with a clean browser? Then proceed like this:

a. First make a backup of your current web browser settings (because you never know why you might need them sometime):

- Launch a terminal window (this is how to launch a terminal window: *Click*).

- Use copy/paste to transfer the following green command line to the terminal:

For Firefox:
cp -r ~/.mozilla ~/.mozillabkp

Press Enter.

For Chrome:
cp -r ~/.config/google-chrome ~/.config/google-chromebkp

Press Enter.

For Chromium:
cp -r ~/.config/chromium ~/.config/chromiumbkp

Press Enter.

b. Now export your bookmarks to a backup file:

For Firefox:
Click the Bookmarks button (the one on the right of the little star) - Show All Bookmarks

Import and Backup - Backup...

Save the bookmarks-xxx.json file to the location you prefer.

Later on, you can import your bookmarks again in a clean Firefox.

For Chrome / Chromium:
On the upper right in your browser window, click on the three dashes - Bookmarks - Bookmark manager

Click on Organize - Export bookmarks to HTML file...

Later on, you can import them again in your clean Chrome / Chromium.

c. You will also lose all of your stored login passwords for websites! Make sure you know them all.

d. Close the web browser you wish to clean.

e. Launch a terminal window (this is how to launch a terminal window: *Click*).

f. Copy/paste this green command line into the terminal:

For Firefox:
rm -r -v ~/.mozilla && rm -r -v ~/.cache/mozilla

Press Enter.

For Chrome:
rm -r -v ~/.config/google-chrome && rm -r -v ~/.cache/google-chrome

Press Enter.

For Chromium:
rm -r -v ~/.config/chromium && rm -r -v ~/.cache/chromium

Press Enter.

g. Launch your web browser again. It should be clean.

h. Import your old bookmarks from the backup you've created. Importing can be done by means of the same feature as the one you've used for exporting.

You're done! From now on, avoid all shady add-ons and extensions, and install only those that you really need and trust.

(continued in the column on the right)


This website is being sponsored by Google Ads.

Are you using an ad blocker? Then you're also blocking my earnings from advertisements....

If you wish to support my website, you can configure your ad blocker to make an exception for this website.

Thanks in advance....


The registry

4. There's no need to clean the registry of Linux, as it can't get polluted in the first place. For the following reasons:

- Only the operating system itself has a central registry. The configurations of the applications aren't in there, because they don't have access to it. So they can't mess it up. They place their own default settings in their own folders in the system.

- applications place upon installation a hidden settings file in the personal folder of each user. That's the only settings file that a user has access to. More or less like MS-DOS did, when each application only created its own .ini file with its settings.

- each user has his own hidden copy of the central registry in his personal folder. That copy is the only thing that he can mess up, not the registry of another user account.

Remove old kernels

5. Unlike Linux Mint, Ubuntu gets kernel updates by default. This happens regularly. After a kernel update, the old kernel still shows in the Grub boot menu, under the header: "Advanced options for Ubuntu". Because you might want to start your machine with the old kernel, if the new kernel doesn't function well.

So far, so good. But having more than one or two redundant kernels, is superfluous and a waste of disk space: each kernel uses up more than 200 MB (headers included). This is how you can remove old kernels and thereby clean up the Grub boot loader menu as well:

a. First install a small collection of tools, like this:

Launch a terminal window.
(You can launch a terminal window like this: *Click*)

Type (use copy/paste to avoid errors):

sudo apt-get install byobu

Press Enter. Type your password when required: your password will remain entirely invisible, not even dots will show when you type it, this is normal. Press Enter.

b. Then copy/paste this line into the terminal, which will remove all kernels except your current kernel and the two latest old ones:

sudo purge-old-kernels

Press Enter.

Finished! That's all you ever need to do. Doing more is risky and not advisable.

Note: don't use cleaning applications like Bleachbit and Computer Janitor for this job. They are dangerous and at best superfluous.

Prevent future disk pollution and pin Ubuntu to a kernel version

5.1. Kernel updates are rarely relevant for ordinary desktop users. That's even true for security updates for kernels, while kernel updates do carry the risk of damaging the stability of your system. That's why they are disabled by default in Linux Mint, for example.

So you might consider to disable kernel updates in Ubuntu as well, by pinning it to its current kernel version. Both for the stability of your system and for preventing future disk pollution. You can do that as follows (item 7, left column).

Make Firefox cleanse itself automatically upon quitting

6. Improve your privacy: you can configure Firefox to cleanse itself automatically, upon quitting. All cookies and history are being deleted then. Furthermore, you can limit the tracking that some websites do to follow you.

The price you pay is a small decrease in user friendliness, but it's not much. The privacy gain is huge, and outweighs this price by far.

You can do it like this:
Panel of Firefox - Edit - Preferences - tab Privacy

a. Item Tracking: set it to:
Tell sites that I do not want to be tracked

b. Item History: change the setting to:
Firefox will: Use custom settings for history

c. Item Cookies: change the setting to:
Keep until: I close Firefox

d. Now tick the following setting:
Clear history when Firefox closes

e. Finally, click the button "Settings..." and tick everything, except for Saved Passwords and Site Preferences. Click OK.

Click Close and you're done.

Tip: sometimes it may come in handy to force a cleansing during your web browsing. Simply by closing Firefox and launching it anew.

Want more tips?

7. Do you want more tips and tweaks for Ubuntu? There's a lot more of them on this website! For example 10 fatal mistakes that you'll want to avoid in Ubuntu.


To the content of this website applies a Creative Commons license.


Comments