2

I'm looking for packages which have following situations :

  1. Deleted but not purged
  2. Installed but not configured

I tried things like

aptitude search '~id'

and

aptitude search "~iuA"

but neither worked.

Any ideas?

Update - one of the commands doesn't work -

[$] dpkg-query -Wf '${db:Status-Abbrev} ${Package}\n' | grep ^i[^i]

zsh: no matches found: ^i[^i]

any ideas if it is zsh at fault or something else ?

2

For your aptitude attempts, it's important to note that ~ doesn't mean 'look for the following flags in a package's status'. ~i is shorthand for ~installed, and then the d is interpreted as a literal d, that is, packages whose names contain the letter d. I looked through the documentation for aptitude (/usr/share/doc/aptitude/html/en/index.html on my system) for a search pattern that would satisfy your question, but I'm not sure it's possible. ~action might get you half-way there, but I'm not sure about getting the status too.


An alternative to using aptitude is to use dpkg-query with grep.

dpkg-query -Wf '${db:Status-Abbrev} ${Package}\n' | grep ^r

This will search for packages that are in the removed state, but not purged.

dpkg-query -Wf '${db:Status-Abbrev} ${Package}\n' | grep ^i[^i]

This will search for packages that are marked to be installed, but are not completely installed. If you do not want to include packages pending on triggers, you can use ^i[ncHUF] instead.


To get only the second column of output (the package name), you can use sed:

dpkg-query -Wf '${db:Status-Abbrev} ${Package}\n' | sed -n 's/^r.R\?\s*//p'

to find removed packages, and

dpkg-query -Wf '${db:Status-Abbrev} ${Package}\n' | sed -n 's/^i[^i]R\?\s*//p'

to find packages to be installed but not completely installed.


To expand on this a bit, Debian packages have two parts to their 'status':

  • The action intended to be performed to a package. This can be to install a package, to remove a package, to hold a package, or to purge a pacakge.

  • The package status, which describes the actual state of the package on your system.

The above dpkg-query invocation lists a package's action and status, one character each, proceeding the package name at the beginning of each line.

To find packages which are removed but not purged, we just search for packages with the 'remove' action: grep ^r. To find packages that are installed, or intended to be installed, but not configured yet, we search for packages whose action is install, but whose status is something other than installed: grep ^i[^i].

  • Actually $aptitude search "?installed" | grep "^id" works just fine. – shirish Sep 26 '16 at 6:47
  • This is semantically different, I believe. This lists packages that are installed, but are set to be deleted. It sounds like you want it the other way around, that is, not fully installed, but set to be installed. It's possible you can get aptitude to give you this output, but I have to ask if there's a reason you want to use aptitude in particular; it's meant to be a UI frontend for apt, whereas dpkg-query is meant to be a lower level interface for this information. – Dylan Frese Sep 26 '16 at 7:58
1

Deleted but not purged is ~c (?config-files).

Installed but not configured is not tracked by apt, only by dpkg. A package has two states: actual and desired. Apt only cares about the desired state. The desired state of a package that's installed but not configured is installed.

See Dylan Frese's answer for the dpkg queries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.