Why is 'apt-cache search' and 'find / -name' showing files associated with a package i have already purged?

Solution 1:

Apt maintains a local database of all available deb package from all currently-known sources. "Available" means that it includes packages that you don't currently have installed as well as the packages that you DO currently have installed.

  • apt-cache searches the database
  • apt update refreshes the database from those sources
  • apt list libreoffice-writer or apt list libreoffice* will specify which packages in the output are installed.

Now let's look at files and directories that remain after a --purge.

  • Directories may remain if they are not empty after apt is done removing files. Some other package (or the admin) may be using the directory, too.

  • Apt will NEVER remove any file located under your /home directory. (The manpage is very clear about that)


A word about using wildcards with apt: Many users are surprised when wildcards cause extra packages to be marked for action, and when packages they expected to be marked aren't.

There could be lots of possible reasons why you get an action different than you expect: Dependencies, unexpected names, misspellings, wrong wildcard, etc.

There are two schools of thought on safe, effective usage of wildcards with apt:

  1. Use apt's --simulate to test the action first. Review your output and find the unexpected BEFORE doing it for real.

  2. Avoid using wildcards at all. Use apt's tools to KNOW the correct packages you want to act upon. Then list those packages.

Solution 2:

apt-cache search searches packages found in your software lists (ie. from data from apt update and doesn't limit itself to installed packages - allowing you to find what you can install etc).

I'm not using Kubuntu & don't have kubuntu-desktop installed; but I can apt-cache search kubuntu-desktop to confirm that package contains what I think it is; it's available for my system, I've remembered the name correctly etc & can then decide to install it. ie. it's searching my software lists cache... not my installed packages.

The package list is updated by the execution of the apt update command. You don't install packages with that command, but when you subsequently use apt install... apt-cache reads from the cache downloaded by the prior apt update command & includes all packages available to your system by sources you have enabled/added (be they installed, or not installed).

Solution 3:

You have to use dpkg --list | grep -i libreoffice to determine LibreOffice related installed packages.

If LibreOffice related files were installed using APT then they should be removed this way. To automate the process use below command:

sudo apt-get autopurge $(dpkg --list | grep -i libreoffice | awk '{print $2}')

and do not remove files controlled by APT manually.


Stuff to read:

  1. man dpkg
  2. man apt
  3. man apt-cache