2

I wanted to "purge" all packages that were "removed" only. After skimming through the manpage of dpkg, I thought the --clear-selections parameter would do the trick. So stupid me typed it in with sudo, and afterwards I checked the selection states again and was shocked.

dpkg has selected all (non-vital) installed packages to get uninstalled!

This was of course my fault, but definitely not intended. So, how do I revert this?

I still have the terminal window open where I ran dpkg --get-selections | grep deinstall both before (85 packages) and after (2614 packages) the accidental command.

What I need now is to subtract the first (old) deinstall list from the second (current) one and mark all those packages as wanted again. Setting them to manual will not be good though, as that would affect hundreds of libraries which make no sense if installed without their applications. So we have to set it to auto and then I probably have to manually find out the top level packages to be selected as manual. Or can something help me there?

Info: I have two separate text files, one containing the first --get-selections output, one the second. They contain only lines with the syntax:

package-name         deinstall

where package-name is, well, the actual package name, and the space in between is an undefined number of tabs.

Update: I just found the output of dpkg --get-selections from before the accident without any grep filtering! Only two packages were installed after that, I can fix them manually later.

Please help me to restore my previous package selections!

  • Is /var/lib/apt/extended_states still intact? If yes, back it up! – Nephente Oct 19 '15 at 12:24
  • @Nephente After having remembered that I still have the full old output of dpkg --get-selections, I could solve the problem. – Byte Commander Oct 19 '15 at 12:29
1

To set all packages currently selected to deinstall back to install, you run the following two commands:

sudo dpkg --get-selections | awk '/deinstall/ {printf "%s\t%s\n",$1,"install"}' > packages
sudo dpkg --set-selections < packages

The first command finds all packages marked with deinstall and writes a list of packages like this

package-name         install

The second command corrects the packages.


If the full output of dpkg --get-selections from before the accident is given, you can simply restore all selections with the command

sudo dpkg --set-selections < packages

where packages is the name of the file holding the old output.

  • First, I need to restore the previous state, where 85 packages were correctly set to deinstall. So I need the difference of the two files where I stored both outputs before and after the bad command and set only them back again. Second, what will it set those to? Is it the same as apt-mark auto or apt-mark manual or something entirely different? – Byte Commander Oct 19 '15 at 11:52

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.