如何正确删除 Arch Linux 中所有已安装的与正则表达式匹配的软件包?

如何正确删除 Arch Linux 中所有已安装的与正则表达式匹配的软件包?

我使用以下命令安装了 TeX Live 2023剧本而不是 Arch Linux 存储库。然而,在安装其他软件时,一些 TeX Live 软件包无论如何都会进入我的桌面,从而导致问题。所以我尝试删除所有texlive包。

texlive这是系统上安装的软件包列表。

$ sudo pacman -Qs texlive*
local/texlive-basic 2023.66594-19 (texlive)
    TeX Live - Essential programs and files
local/texlive-bin 2023.66984-16
    TeX Live binaries
local/texlive-binextra 2023.66594-19 (texlive)
    TeX Live - TeX auxiliary programs
local/texlive-context 2023.66594-19 (texlive)
    TeX Live - ConTeXt and packages
local/texlive-fontsextra 2023.66594-19 (texlive)
    TeX Live - Additional fonts
local/texlive-fontsrecommended 2023.66594-19 (texlive)
    TeX Live - Recommended fonts
local/texlive-fontutils 2023.66594-19 (texlive)
    TeX Live - Graphics and font utilities
local/texlive-games 2023.66594-19 (texlive)
    TeX Live - Games typesetting
local/texlive-langcjk 2023.66594-19 (texlive-lang)
    TeX Live - Chinese/Japanese/Korean (base)
local/texlive-langenglish 2023.66594-19 (texlive-lang)
    TeX Live - US and UK English
local/texlive-langgreek 2023.66594-19 (texlive-lang)
    TeX Live - Greek
local/texlive-langjapanese 2023.66594-19 (texlive-lang)
    TeX Live - Japanese
local/texlive-langkorean 2023.66594-19 (texlive-lang)
    TeX Live - Korean
local/texlive-langother 2023.66594-19 (texlive-lang)
    TeX Live - Other languages
local/texlive-latex 2023.66594-19 (texlive)
    TeX Live - LaTeX fundamental packages
local/texlive-latexextra 2023.66594-19 (texlive)
    TeX Live - LaTeX additional packages
local/texlive-latexrecommended 2023.66594-19 (texlive)
    TeX Live - LaTeX recommended packages
local/texlive-luatex 2023.66594-19 (texlive)
    TeX Live - LuaTeX packages
local/texlive-mathscience 2023.66594-19 (texlive)
    TeX Live - Mathematics, natural sciences, computer science packages
local/texlive-metapost 2023.66594-19 (texlive)
    TeX Live - MetaPost and Metafont packages
local/texlive-music 2023.66594-19 (texlive)
    TeX Live - Music packages
local/texlive-pictures 2023.66594-19 (texlive)
    TeX Live - Graphics, pictures, diagrams
local/texlive-plaingeneric 2023.66594-19 (texlive)
    TeX Live - Plain (La)TeX packages
local/texlive-xetex 2023.66594-19 (texlive)
    TeX Live - XeTeX and packages

首先,我尝试提供数据pacman -Spacman -R但由于并非每个texlive软件包都已安装,因此没有继续进行。

$ sudo pacman -R $(pacman -Ssq texlive*)
error: target not found: tectonic
error: target not found: texlive-bibtexextra
error: target not found: texlive-doc
error: target not found: texlive-formatsextra
error: target not found: texlive-humanities
error: target not found: texlive-langarabic
error: target not found: texlive-langchinese
error: target not found: texlive-langcyrillic
error: target not found: texlive-langczechslovak
error: target not found: texlive-langeuropean
error: target not found: texlive-langfrench
error: target not found: texlive-langgerman
error: target not found: texlive-langitalian
error: target not found: texlive-langpolish
error: target not found: texlive-langportuguese
error: target not found: texlive-langspanish
error: target not found: texlive-meta
error: target not found: texlive-pstricks
error: target not found: texlive-publishers

所以我需要以某种方式进行过滤pacman -Q。经过我有限的知识和参数扩展的多次尝试,grep我提取了包名称。

$ for i in $(sudo pacman -Qs texlive* | grep -Eo '^local/[[:alpha:]]+-[[:alpha:]]+')
do
    echo ${i:6}
done
texlive-basic
texlive-bin
texlive-binextra
texlive-context
texlive-fontsextra
texlive-fontsrecommended
texlive-fontutils
texlive-games
texlive-langcjk
texlive-langenglish
texlive-langgreek
texlive-langjapanese
texlive-langkorean
texlive-langother
texlive-latex
texlive-latexextra
texlive-latexrecommended
texlive-luatex
texlive-mathscience
texlive-metapost
texlive-music
texlive-pictures
texlive-plaingeneric
texlive-xetex

然后我替换echosudo pacman -R运行代码。

$ for i in $(sudo pacman -Qs texlive* | grep -Eo '^local/[[:alpha:]]+-[[:alpha:]]+')
do
    sudo pacman -R ${i:6}
done
checking dependencies...
error: failed to prepare transaction (could not satisfy dependencies)
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-binextra
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-context
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-fontsextra
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-fontsrecommended
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-fontutils
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-langcjk
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-langenglish
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-langgreek
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-langother
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-latex
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-luatex
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-metapost
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-pictures
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-plaingeneric
:: removing texlive-basic breaks dependency 'texlive-basic' required by texlive-xetex
checking dependencies...
error: failed to prepare transaction (could not satisfy dependencies)
:: removing texlive-bin breaks dependency 'texlive-bin' required by dvisvgm
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-basic
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-binextra
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-context
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-fontsextra
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-fontsrecommended
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-fontutils
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-games
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langcjk
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langenglish
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langgreek
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langjapanese
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langkorean
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-langother
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-latex
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-latexextra
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-latexrecommended
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-luatex
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-mathscience
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-metapost
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-music
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-pictures
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-plaingeneric
:: removing texlive-bin breaks dependency 'texlive-bin' required by texlive-xetex
checking dependencies...
:: python-matplotlib optionally requires texlive-binextra: usetex dependencies

Packages (1) texlive-binextra-2023.66594-19

Total Removed Size:  112.67 MiB

:: Do you want to remove these packages? [Y/n] y
:: Processing package changes...
(1/1) removing texlive-binextra                                 [##################################] 100%
:: Running post-transaction hooks...
(1/3) Arming ConditionNeedsUpdate...
(2/3) Updating TeXLive filename database...
(3/3) Updating TeXLive format files...
Can't locate mktexlsr.pl in @INC (@INC entries checked: //tlpkg //texmf-dist/scripts/texlive /usr/lib/perl5/5.38/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/5.38/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/5.38/core_perl /usr/share/perl5/core_perl) at /usr/bin/fmtutil line 23.
BEGIN failed--compilation aborted at /usr/bin/fmtutil line 25.
error: command failed to execute correctly
checking dependencies...

Packages (1) texlive-context-2023.66594-19

Total Removed Size:  52.81 MiB

:: Do you want to remove these packages? [Y/n] y   
:: Processing package changes...
(1/1) removing texlive-context                                  [##################################] 100%
:: Running post-transaction hooks...
(1/3) Arming ConditionNeedsUpdate...
(2/3) Updating TeXLive filename database...
(3/3) Updating TeXLive font maps...
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
updmap [ERROR]: The following map file(s) couldn't be found:
updmap [ERROR]:     dvips35.map (in builtin)
updmap [ERROR]:     pdftex35.map (in builtin)
updmap [ERROR]:     ps2pk35.map (in builtin)
updmap [ERROR]: Did you run mktexlsr?

    You can disable non-existent map entries using the option
      --syncwithtrees.

error: command failed to execute correctly
checking dependencies...

Packages (1) texlive-fontsextra-2023.66594-19

Total Removed Size:  1433.62 MiB

:: Do you want to remove these packages? [Y/n] y
:: Processing package changes...
(1/1) removing texlive-fontsextra                               [##################################] 100%
:: Running post-transaction hooks...
(1/3) Arming ConditionNeedsUpdate...
(2/3) Updating TeXLive filename database...
(3/3) Updating TeXLive font maps...
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2158.
Use of uninitialized value $fn in concatenation (.) or string at /usr/bin/updmap line 2159.
updmap: open() failed: No such file or directory at /usr/bin/updmap line 2159.
updmap [ERROR]: The following map file(s) couldn't be found:
updmap [ERROR]:     dvips35.map (in builtin)
updmap [ERROR]:     pdftex35.map (in builtin)
updmap [ERROR]:     ps2pk35.map (in builtin)
updmap [ERROR]: Did you run mktexlsr?
...

我必须多次运行上述命令,因为要删除的包相互依赖。几次运行后,texlive包完全消失了。

$ sudo pacman -Qs texlive*

虽然它在这种情况下确实有效,但这是不可靠的,因为我使用正则表达式进行查询,然后再次依赖另一个正则表达式进行 grep 查询。如果任何texlive包的名称中包含数字,则该方法将不起作用。是否有一种更简洁的方法来清除所有与单个正则表达式匹配的包,仅pacman在可能的情况下使用?我是否可以删除它们而不提示对每个包都说“是”?

答案1

-Q如果使用该选项,则可以仅列出包名称q。因此,这应该提供已安装软件包的列表(我的系统的输出,你的系统会有所不同):

$ pacman -Qsq 'texlive*'
texlive-basic
texlive-bin
texlive-fontsextra
texlive-langgreek
texlive-latex
texlive-latexextra
texlive-latexrecommended
texlive-pictures

顺便说一下,请注意如何'texlive*'用引号括起来。这很重要,因为未加引号的内容*将由 shell 扩展调用,因此如果当前目录中pacman有任何匹配的文件或目录,那么如果不引用,这些文件或目录将被传递到。texlive*pacman

现在我们有了列表,我们还需要确保删除所有依赖项以及依赖于您要删除的内容的任何包。所以我们需要以下删除选项(来自man pacman):

删除选项(适用于 -R)

-c,--级联

删除所有目标包,以及依赖于一个或多个目标包的所有包。此操作是递归的,必须小心使用,因为它可能会删除许多可能需要的包。

-s, --递归

删除指定的每个目标,包括其所有依赖项,前提是 (A) 其他包不需要它们; (B) 它们不是由用户明确安装的。此操作是递归的,类似于向后 --sync 操作,它有助于保持干净的系统,没有孤儿。如果要省略条件 (B),请传递此选项两次。

因此,要删除所有相关包,请使用:

sudo pacman -Rcs $(pacman -Qsq 'texlive*')

在我的系统上,这将是:

$ sudo pacman -Rcs $(pacman -Qsq 'texlive*')
checking dependencies...
:: evince optionally requires texlive-bin: DVI support
:: python-matplotlib optionally requires texlive-latexrecommended: usetex usage with pdflatex
:: python-sphinx optionally requires texlive-latexextra: for generation of PDF documentation
:: r optionally requires texlive-bin: latex sty files
:: xournalpp optionally requires texlive-latexextra: LaTeX package

Packages (15) dvisvgm-3.1.1-1  ffcall-2.4-2  fontawesome.sty-4.6.3.2-1  libsigsegv-2.14-2  otf-font-awesome-6.4.2-1
              t1lib-5.1.2-8  zziplib-0.13.72-2  texlive-basic-2023.66594-19  texlive-bin-2023.66984-16
              texlive-fontsextra-2023.66594-19  texlive-langgreek-2023.66594-19  texlive-latex-2023.66594-19
              texlive-latexextra-2023.66594-19  texlive-latexrecommended-2023.66594-19  texlive-pictures-2023.66594-19

Total Removed Size:  1786.02 MiB

相关内容