“sudo apt-get install foo-” 导致删除 foo 包和所有依赖它的东西

mel*_*lmi 10 command-line apt

在命令提示符下工作时,我不小心输入了以下命令:

sudo apt-get install python3-
Run Code Online (Sandbox Code Playgroud)

和 ubuntu 开始删除 python3 和所有依赖它的东西(包括 Firefox 等等)。幸运的是,我立即关闭了该终端并通过检查dpkg日志文件恢复了所有内容,但我想知道为什么install命令应该像删除一样?

这是一个错误吗?

考虑这样一种情况,您正在查找包名称(按 Tab 两次)并通过按 Enter 键来检查可能性,而这些 Enter 键保留在键盘缓冲区中,并且.... youhaaaa...apt-get正在删除整个安装你的眼睛。

jok*_*ino 11

这显然是apt.

联机帮助页apt-get命令联机帮助页图标,

如果将连字符附加到包名称(中间没有空格),则如果安装了已识别的包,则将删除该包。同样,加号可用于指定要安装的软件包。后面的这些功能可用于覆盖 apt-get 的冲突解决系统做出的决定。


使用已安装的包和附加到包末尾的连字符进行模拟,得到以下输出:

$ apt-get install -s retext-
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  retext-wpgen
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
  retext
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Remv retext [3.1.3-1]
Run Code Online (Sandbox Code Playgroud)

同样,使用卸载的包并在包末尾附加一个加号,我得到以下输出:

$ apt-get remove -s googlecl+
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  python-gdata
Suggested packages:
  python-gdata-doc
The following NEW packages will be installed:
  googlecl python-gdata
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Inst python-gdata (2.0.17-1 Ubuntu:12.10/quantal [all])
Inst googlecl (0.9.13-1.1 Ubuntu:12.10/quantal [all])
Conf python-gdata (2.0.17-1 Ubuntu:12.10/quantal [all])
Conf googlecl (0.9.13-1.1 Ubuntu:12.10/quantal [all])
Run Code Online (Sandbox Code Playgroud)


Nic*_*Tux 10

刚刚在包裹后尝试了这个减号(或破折号),是的,apt-get 表现得像remove.

有趣的是我不知道apt-get. 这个减号对每个包裹都有效。我试着用smplayer-firefox-,总是表现得像remove。所以我唯一能想到的是包末尾的破折号被apt-get像减号和install命令一样考虑转换为remove.

如果你想安装关于 python3 的所有东西,那么你必须在这个破折号(减号)后面添加一个星号

sudo apt-get install python3-*

一开始我以为这只是一个冲突问题,但事实并非如此。有时,当您安装某个包并与其他包冲突时,由于新安装的包,已安装的包将被删除,但这不是我们这里的情况。

我们今天学到了一些有用的东西。

来自 apt-get 的手册页。要通过终端阅读手册页,请提供man apt-get

如果将连字符 (-) 附加到包名称(中间没有空格),则标识的包将被删除(如果当前已安装)。同样,加号 (+) 可用于指定要安装的软件包。后面的这些功能可用于覆盖 apt-get 的冲突解决系统做出的决定。

最终不是一个新选项或奇怪的东西,只是我们没有仔细阅读手册页。