handbook, books, note, tutorial, troubleshooting

Remove Unnecessary Configuration Files On Linux (Debian-based Systems)

Remove Unnecessary Configuration Files On Linux

(Debian-based Systems)

There is a  difference between –  apt remove vs apt purge vs apt autoremove vs apt clean vs apt autoclean. These are the commands that we use to remove the packages, config files of removed packages and clean the local cache in any Debian-based systems.
  1. apt remove – This command is used to remove a package but leave all of its configuration files in place. When you reinstall the same package later, all of your settings will still be intact.
  2. apt purge – It is the same as “apt remove” command but also removes all of the configuration files.
  3. apt autoremove – It removes any packages on your Deb-based system that are no longer required. Those packages are called unused packages. So, the “autoremove” command simply removes packages that hasn’t been installed manually by the user and that’s not needed by any other package in your system.
  4. apt clean – When you use apt to install or update something from the repositories, it first downloads all the required packages to your local drive and then installs them. The “apt-get clean” command removes those downloaded packages. It doesn’t uninstall any package, it just cleans that cache.
  5. apt autoclean – Like “apt clean”, the “apt autoclean” command clears out the local repository of retrieved package files. The difference is that it removes all stored archives in your cache for packages that can not be downloaded anymore.

Find all packages that are removed but not purged in Debian, Ubuntu
First, let us list the leftover files in the system using dpkg command:
$ dpkg -l | grep ^rc
$ dpkg -l | grep "^rc"
This command will list all packages that have been removed but not purged.
You can also use the following apt command to list all packages that are removed but not purged:
$ apt list | grep 'residual-config'
Another way to list the leftovers from your Debian system is to use Synaptic package manager.
If Synaptic package manager is not installed, you can install it using command:
$ sudo apt install synaptic
Remove Unnecessary Configuration Files On Debian-based Systems
There are couple ways to do this. I have given three methods to remove unwanted config files from Debian and its derivatives.

Using aptitude:

This is the easiest and shortest command to delete unnecessary configuration files from your Debian-based system:
$ sudo aptitude purge ~c
$ sudo aptitude purge ?config-files
Please note that the aptitude command is not pre-installed by default. You can install it using the command:
$ sudo apt install aptitude
Alternatively, use the following command to delete the unwanted config files:
$ sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`

Using dpkg command:

If you don’t have aptitude installed, you can use dpkg to purge unwanted config files.
To find and delete unused config files using dpkg, run:
$ dpkg -l | grep "^rc" | awk '{print $2}' | sudo xargs dpkg -P
$ dpkg -l | grep "^rc" | awk '{print $2}' | sudo xargs dpkg --purge

Remove Unnecessary Configuration Files On Linux (Debian-based Systems)