恢复意外的“dpkg --clear-selections”

Byt*_*der 7 package-management apt dpkg

我只想“清除”所有“删除”的软件包。浏览完 的联机帮助页后dpkg,我认为该--clear-selections参数可以解决问题。太愚蠢了,我用 键入了它sudo,然后我再次检查了选择状态并感到震惊。

dpkg已选择所有(非重要)已安装的软件包进行卸载!

这当然是我的错,但绝对不是我故意的。那么,我该如何恢复这个状态呢?

我仍然打开终端窗口,在意外命令之前(85 个包)和之后(2614 个包)dpkg --get-selections | grep deinstall运行该窗口。

我现在需要的是从第二个(当前)卸载列表中减去第一个(旧)卸载列表,并再次将所有这些软件包标记为需要的。不过,将它们设置为manual不好,因为这会影响数百个库,如果没有应用程序安装这些库就毫无意义。所以我们必须将其设置为auto,然后我可能必须手动找出要选择为的顶级包manual。或者有什么可以帮助我的吗?

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
Run Code Online (Sandbox Code Playgroud)

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!

A.B*_*.B. 5

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
Run Code Online (Sandbox Code Playgroud)

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

package-name         install
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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