为什么 apt 在给 * 作为后缀时会删除不需要的包?

die*_*lar 4 apt

我做了一个sudo apt-get remove ruby*然后我看到一些 grub 包也被删除了所以我去安装回那些日志显示已删除的包

/sda在重新安装时,我将 grub 设置为在我的(一般来说,不是任何数字)上工作。

应该一切都好还是我应该担心我的系统并计划安装/重新配置更多的 grub。

而且,为什么会这样?

Rad*_*anu 8

如果您不确切知道自己在做什么,则不应使用:

sudo apt-get remove package.*
#                          ? or any other character in the place of dot
Run Code Online (Sandbox Code Playgroud)

因为这可能会删除意外的包并导致比它解决的问题更多的问题。在package.*将匹配包含字符串的所有软件包(及其依赖)package在他们的名字。这是从man apt-get,在第 110 行的某处:

       If no package matches the given expression and the expression
       contains one of '.', '?' or '*' then it is assumed to be a POSIX
       regular expression, and it is applied to all package names in the
       database. Any matches are then installed (or removed). Note that
       matching is done by substring so 'lo.*' matches 'how-lo' and
       'lowest'. If this is undesired, anchor the regular expression with
       a '^' or '$' character, or create a more specific regular
       expression.
Run Code Online (Sandbox Code Playgroud)

这是来自正则表达式/POSIX 基本正则表达式维基教科书:

* 匹配前面的元素零次或多次。例如,ab*c匹配“ ac ”、“ abc ”、“ abbbc ”等,[xyz]*匹配“”、“ x ”、“ y ”、“ z ”、“ zx ”、“ zyx ”、“ xyzzy ”等。\(ab\)*匹配“”、“ ab ”、“ abab ”、“ ababab ”等。

无论如何,如果您真的想运行类似sudo apt-get remove package.*(or sudo apt-get remove packagey*, or sudo apt-get remove packagec*- 在这种情况下都是相同的),请首先使用-s( --simulate) 选项运行它以查看它会做什么(man apt-get有关更多信息,请参见)。

现在,我认为您可以使用以下两个步骤来解决您的问题:

  1. 重新安装您删除的所有软件包

  2. 仅删除ruby:

    sudo apt-get remove ruby
    
    Run Code Online (Sandbox Code Playgroud)

    或者,如果您想删除所有以以下名称开头的软件包ruby:

    sudo apt-get remove ^ruby
    
    Run Code Online (Sandbox Code Playgroud)

    但最好先模拟:

    apt-get -s remove ^ruby
    
    Run Code Online (Sandbox Code Playgroud)

  • 如果从包含任何以 `package` 开头的文件的目录运行,`package*` 也会以令人惊讶的方式运行。最好引用它:`'package*'` (3认同)
  • +1 对于广为人知的`-s` 选项。 (2认同)

归档时间:

查看次数:

779 次

最近记录:

12 年,1 月 前