如何僅解除安裝 Libre Office 的一個版本?

如何僅解除安裝 Libre Office 的一個版本?

我安裝了 Libre Office 的兩個版本 - 4.3 和預設版本:

dpkg --get-selections | grep -v deinstall | grep libreoffice

節目

libreoffice-avmedia-backend-gstreamer
libreoffice-base-core
libreoffice-calc
libreoffice-common
libreoffice-core
libreoffice-draw
libreoffice-help-en-gb
libreoffice-help-en-us
libreoffice-impress
libreoffice-l10n-en-gb
libreoffice-l10n-en-za
libreoffice-math
libreoffice-pdfimport
libreoffice-style-galaxy
libreoffice-writer
libreoffice4.3
libreoffice4.3-base
libreoffice4.3-calc
libreoffice4.3-debian-menus
libreoffice4.3-dict-en
libreoffice4.3-dict-es
libreoffice4.3-dict-fr
libreoffice4.3-draw
libreoffice4.3-en-us
libreoffice4.3-impress
libreoffice4.3-math
libreoffice4.3-ure
libreoffice4.3-writer

我只想要libreoffice4.3-*又不要libreoffice^/(?!4.3)-*

有沒有辦法在指令中使用這種正規表示式apt-get


答案1

apt-get接受 POSIX 正規表示式(不是 shell 樣式的通配符):

sudo apt-get remove '^libreoffice4.3-*'

將刪除

libreoffice4.3
libreoffice4.3-base
libreoffice4.3-calc
libreoffice4.3-debian-menus
libreoffice4.3-dict-en
libreoffice4.3-dict-es
libreoffice4.3-dict-fr
libreoffice4.3-draw
libreoffice4.3-en-us
libreoffice4.3-impress
libreoffice4.3-math
libreoffice4.3-ure
libreoffice4.3-writer

以及那些依賴他們的人。 (這就是為什麼apt-get remove libreoffice4*不做你認為會做的事情。)

所以試試:

sudo apt-get remove '^libreoffice-.*' libreoffice

這將刪除:

libreoffice-avmedia-backend-gstreamer
libreoffice-base-core
libreoffice-calc
libreoffice-common
libreoffice-core
libreoffice-draw
libreoffice-help-en-gb
libreoffice-help-en-us
libreoffice-impress
libreoffice-l10n-en-gb
libreoffice-l10n-en-za
libreoffice-math
libreoffice-pdfimport
libreoffice-style-galaxy
libreoffice-writer
libreoffice

man apt-get:

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.

相關內容