Back to the home page

As the Victorians used to say: cleanliness is next to godliness. So here are some tips to make your Ubuntu 22.04 even more divine.
Contents of this page:
- 1. Clear the updates cache
- 2. Clear the thumbnail cache
- 3. Want to get rid of polluted settings in your web browser?
- 4. The registry
- 5. (obsoleted)
- 6. Make Firefox cleanse itself automatically upon quitting
- 7. Remove most Asian fonts
- 8. Set a reasonable maximum log size for systemd
- 9. Reduce other system logs
- 10. Turn off the firewall log
- 11. Want more tips?
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.
Note: This is the how-to for cleaning Ubuntu. The how-to for cleaning Linux Mint is here.
Ubuntu doesn't get polluted much over time (with one notable exception, namely old kernels. More about that later). It doesn't even need defragmentation. The only cleansing actions you might want to do in Ubuntu, are the following:
Clear the updates cache
1. First of all, use the application Software to install Synaptic Package Manager.Then, on the bottom left, click on the big square button with the rows of white dots (Show Applications). Query: synaptic
Click on Synaptic Package Manager
Settings - Preferences - Files
Select: Delete downloaded packages after installation
Press the button: Delete cached package files
Clear the thumbnail cache
2. For each displayed 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. By default, only thumbnails older than six months will be deleted.
The quickest way to get rid of all the thumbnails is to use the terminal for deleting the folder in which they reside. No worries: the system will re-create that folder and its subfolders automatically, the next time that thumbnails will be generated. Proceed like this:
Launch a terminal window.
(You can launch a terminal window like this: *Click*)
Type (use copy/paste to avoid errors):
rm -rfv ~/.cache/thumbnails
Press Enter.
Note: This will probably affect the thumbnails on your desktop as well; in that case it should suffice to simply log out and in again (or reboot your computer), 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-editor 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 (days, press Enter to confirm) and the maximum-size to 64 (MB, again press Enter to confirm).
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 or Chrome (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 blue command line to the terminal:
For Firefox:
cp -r -v ~/.mozilla ~/.mozillabackup
Press Enter.
For Chrome:
cp -r -v ~/.config/google-chrome ~/.config/google-chromebackup
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:
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.
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 blue 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.
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.
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.
(obsoleted)
5. Obsoleted.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.
Remove most Asian fonts
7. If you're not a user of Asian fonts, you might remove a couple of those. That should free up several hundred MB's of disk space, but more importantly: the font selection box in Libre Office will become much less cluttered.Note: Sometimes, removing fonts may have unwanted side effects! I haven't experienced those on my machines after the removal of the Asian fonts described below, which is why I recommend removing them. But your mileage may vary, so proceed with caution: for example, if you have installed MythTV, this removal might also remove MythTV. It's especially something to keep in mind, when you wish to remove even more fonts....
This is how to remove most Asian fonts:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste the following command line into the terminal, in order to avoid typing errors. It's one huge line:
sudo apt-get remove "fonts-kacst*" "fonts-khmeros*" fonts-lklug-sinhala fonts-guru-extra "fonts-nanum*" fonts-noto-cjk "fonts-takao*" fonts-tibetan-machine fonts-lao fonts-sil-padauk fonts-sil-abyssinica "fonts-tlwg-*" "fonts-lohit-*" fonts-beng-extra fonts-gargi fonts-gubbi fonts-gujr-extra fonts-kalapi "fonts-samyak*" fonts-navilu fonts-nakula fonts-orya-extra fonts-pagul fonts-sarai "fonts-telu*" "fonts-wqy*" "fonts-smc*" fonts-deva-extra fonts-sahadeva
Press Enter. Your password will remain entirely invisible, not even dots will show when you type it, that's normal. Press Enter again.
c. Just to make sure, follow it up with this terminal command:
sudo dpkg-reconfigure fontconfig
Press Enter.
d. Reboot your machine.
Finally: I strongly advise to leave it at that. Don't remove any other fonts, because of the aforementioned risk of negative side effects!
How to undo: re-installing removed Asian fonts
7.1. Regrets? If you want to re-install the Asian fonts that you've removed by applying the how-to in item 7, simply replace the word "remove" by "install" in its removal command line. Run dpkg-reconfigure fontconfig again, reboot and all should be like it was before.Set a reasonable maximum log size for systemd
8. The logs of systemd can sometimes grow too big. This is how to reduce their size to a sensible minimum:a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. First you're going to reduce their current size well below 100 MB, which should be more than enough in almost all circumstances. For that one-time action, copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo journalctl --vacuum-size=40M
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
c. When that one-time job is done, you're going to put a permanent size cap of 100 MB on the logs. For setting that size cap, copy/paste the following command line into the terminal, in order to avoid typing errors. It's one big line:
sudo sed -i 's/#SystemMaxUse=/SystemMaxUse=100M/' /etc/systemd/journald.conf
Press Enter.
d. Now you're going to put a permanent number cap of seven log files on the logs. Which equals seven boot procedures.
For setting that number cap, copy/paste the following command line into the terminal, in order to avoid typing errors. It's one big line:
sudo sed -i 's/#SystemMaxFiles=100/SystemMaxFiles=7/g' /etc/systemd/journald.conf
Press Enter.
e. Then apply the new settings, with this terminal command (use copy/paste to transfer it into the terminal):
sudo journalctl --rotate
Press Enter.
You're done!
Reduce other system logs
9. Besides taming the logs of systemd, as described in item 8 on this page, you can also reduce some other system logs. Under normal circumstances this won't free up as much disk space as limiting the systemd logs, but it's always fun to restrict system log files to a sensible minimum....Proceed as follows:
a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. First you're going to delete current system logs. For that one-time action, copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo rm -v /var/log/*.log* /var/log/syslog*
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
c. Now you're going to reduce the number of kept logs to 1, for two types of logs, in the settings file rsyslog. For the first log type, copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo sed -i 's/rotate 7/rotate 1/g' /etc/logrotate.d/rsyslog
Press Enter.
Then copy/paste this command into the terminal for the second log type:
sudo sed -i 's/rotate 4/rotate 1/g' /etc/logrotate.d/rsyslog
Press Enter.
d. Then you're going to set the log rotation for rsyslog to daily instead of weekly. Log rotation simply means starting afresh: you're going to configure your system to start each day with a new empty log, thus limiting its potential size. Proceed like this:
Copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo sed -i 's/weekly/daily/g' /etc/logrotate.d/rsyslog
Press Enter.
e. Now you're going to reduce the number of kept logs to 1, in another settings file named logrotate.conf. Copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo sed -i 's/rotate 4/rotate 1/g' /etc/logrotate.conf
Press Enter.
f. Then you're going to set the log rotation in logrotate.conf to daily instead of weekly. Copy/paste the following command line into the terminal, in order to avoid typing errors:
sudo sed -i 's/weekly/daily/g' /etc/logrotate.conf
Press Enter.
g. Finally, reboot your computer.
You're done!
Turn off the firewall log
10. Have you enabled the firewall ufw (which is recommended)? Then you'll probably never look at its logs, so it won't hurt to turn off all logging by the firewall. Especially because it can be rather spammy sometimes. Turning off its log can be done like this:a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)
b. Copy/paste this blue line into the terminal:
sudo ufw logging off
Press Enter. Type your password when prompted. In Ubuntu this remains entirely invisible, not even dots will show when you type it, that's normal. In Mint this has changed: you'll see asterisks when you type. Press Enter again.
Regrets? Then turn firewall logging on again like this
10.1. Do you want to enable logging by the firewall again? Then use the following terminal command to turn firewall logging on again with the default amount of activity (low):sudo ufw logging low
All should be then, as it was before.
Want more tips?
Do you want more tips and tweaks? There's a lot more of them on this website!For example:
Avoid 10 fatal mistakes
To the content of this website applies a Creative Commons license.
Back to the home page
Disclaimer