Clean up configuration residue packages in Ubuntu
With Ubuntu, like any operating system, obsolete or unnecessary files are not automatically destroyed. However it is possible to remove them and to save space using packages.
Packages
Remove Obsolete Configuration Files
-
Upon uninstalling a package, configuration files are not destroyed in anticipation of a future re-installation of the package.
- To purge unused configuration files, use this command (in a terminal):
-
sudo dpkg --purge $(COLUMNS=200 dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2)
- Note that: it is also possible to delete the config files when uninstalling a package via
- Synaptic, by checking the "complete removal".
- Adept Manager using "Request Purge".
- Using the --purge command.
sudo aptitude remove name-of-package --purge
How to remove the packages in the cache?
When you download and install packages, they are cached to avoid having to download them again.
To remove these packages, there are two commands that can be used: aptitude or apt-get (aptitude is better):
- autoclean removes packages that can't be downloaded.
- clean removes all cached package.
Therefore type:
sudo aptitude autoclean sudo aptitude clean
Kernels
When the kernel is updated, older versions are still installed.To remove a version of a kernel, you must know the exact name of the package, which is linux-image-kernel.version-indexofimage-generic
The best way is to try and uninstall the old kernels via your package manager.
- Start your manager root mode
- kdesu adept_manager if you have kde and adept,
- gksu synaptic for synaptic and Gnome (or Xfce)), then search for the "linux-image".
- If you have adept, uncheck "not installed" in the display (below the search bar).
- If you have synaptic, sort the packages installed first via the first column
- If you have multiple versions of the kernel, or you have different images of the same kernel, you can uninstall the older ones.
It is advisable to always retain the last two versions at least. If an update should go wrong for the last kernel version, it is still possible to revert to an older version, instead of going through a liveCD.
Logfiles
The /var/log directory contains the logs of most services and software. If they are useful for solving problems, still they occupy much space.
Most services perform a log rotation (in order to keep a limited number) or limit their size, but not always.
To be completed (or even delete old log files)
Recycle bin/Trash
Do not forget to empty the Trash bin regularly under Linux. For this, use the following command line:
rm -r -f ~/.local/share/Trash/files/*
Thumbnails of Images
When you're browsing on the internet, Linux stores the thumbnails of images in order to facilitate their future loading ... Usually they are not removed.
The code below will allow the removal of miniatures over 7 days.
find ~/.thumbnails -type f -atime +7 -exec rm {} \;
Configuration Residues in Directories/Home
Even though you have uninstalled a software and/or having their configuration files purged from the /etc directory, the software may have left the configuration files in the home directory of each user.
- For example, the MPlayer software leaves files in the ~/.Mplayer directory.
- It's the same for most applications.
- Note that: These files may take significant proportions.
- For example, Google Earth stores a cache (of at least 200MB) in the home directory of each user
Additional Steps
To gain more space and remove other unnecessary files, you can also empty the trash.
- Note that: for the partitions on external drives (USB keys, MP3 players, NTFS partition ...), Nautilus (the file browser of ubuntu) creates a folder.Trash-username containing the deleted files.
- Remember to also delete this folder (Press CTRL + H in Nautilus to see hidden files).
- To be completed
Automation of tasks
- Simply create files containing these commands:
- For obselete configuration files:
pkg --purge $(COLUMNS=200 dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2)
- For packages stored in cache:
sudo aptitude clean
- And follow the instruction from this FAQ: Automate tasks with cron and init.