Post

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

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

Ubuntu

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.

  • 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.
  • apt purge – It is the same as “apt remove” command but also removes all of the configuration files.
  • 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.
  • 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.
  • 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:

1
$ dpkg -l | grep ^rc

Or,

1
$ 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:

1
$ 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:

1
$ 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:

1
$ sudo aptitude purge ~c

Or,

1
$ sudo aptitude purge ?config-files

Please note that the aptitude command is not pre-installed by default. You can install it using the command:

1
$ sudo apt install aptitude

Alternatively, use the following command to delete the unwanted config files:

1
$ 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:

1
$ dpkg -l | grep "^rc" | awk '{print $2}' | sudo xargs dpkg -P

Or,

1
$ dpkg -l | grep "^rc" | awk '{print $2}' | sudo xargs dpkg --purge

Hi there 👋 Support me!

Life is an echo—what you send out comes back.

Donate

This post is licensed under CC BY 4.0 by the author.