如何删除与特定模式匹配的所有包?

Aar*_*lla 28 aptitude apt

我想卸载 libreoffice。该程序由大约三打模块组成。理想情况下,它们可以通过以下方式删除:

aptitude remove libreoffice3.6* libreoffice-debian-menus libobasis3.6-*
Run Code Online (Sandbox Code Playgroud)

但这失败了

Couldn't find any package whose name or description matched "libreoffice3.6*"
Run Code Online (Sandbox Code Playgroud)

等等。

如何按模式删除一组包?

PS:我很高兴与使用的答案dpkg还是apt,太

Fli*_*imm 36

  1. 使用apt-get、不使用aptitude和使用正则表达式。

  2. 在正则表达式中,.表示任何字符,*表示零次或多次。因此该表达式libreoffice.*匹配任何包含字符串的包名称libreoffice,后跟任意数量的字符。

  3. 用单引号将正则表达式括起来,以避免 shell 解释星号。(如果您libreoffice.example在当前目录中有一个名为example的文件,shell 将替换libreoffice.*libreoffice.example,因此您必须使用单引号来阻止这种行为。)

结果:

sudo apt-get remove 'libreoffice.*'
Run Code Online (Sandbox Code Playgroud)

  • 对于那些想要对此进行测试的人,请使用选项 `--dry-run` 来查看将在不更改系统的情况下删除哪些内容。 (4认同)

aal*_*aap 10

另一种选择是:

dpkg -l | grep libreoffice | awk '{print $2}' | xargs -n1 echo
Run Code Online (Sandbox Code Playgroud)

这将列出所有匹配的包libreoffice。当你确认,他们都是你想摆脱的,运行以下命令谨慎

dpkg -l | grep libreoffice | awk '{print $2}' | xargs -n1 sudo apt-get purge -y
Run Code Online (Sandbox Code Playgroud)

想法:

  1. 让系统列出所有已安装的包
  2. 过滤以仅显示匹配的 libreoffice
  3. 过滤以仅显示包含包名称的列
  4. 在每个包上运行清除命令

  • 我可以给你 +1 现在你让它更安全了:) (2认同)

Bra*_*iam 5

Aptitude 支持全局模式,还有另一个非常酷的匹配项,如下所示:

aptitude remove '?and(?name(libreoffice), name(3.6), ~i)' libreoffice-debian-menus
Run Code Online (Sandbox Code Playgroud)

这将匹配在它的名称的任何包装libreoffice3.6也它的安装(这是什么~i代表。