可以使用哪些标志来pacman -S
仅显示那些尚未安装的软件包?
如果设计无法完成,将接受 shell 脚本。谢谢。
答案1
第一次尝试后得到了相反的答案,谢谢杰夫·夏勒。这是一个小脚本,用于过滤掉已安装的软件包并仅显示未安装的软件包。
#!/bin/sh
installed=$(pacman -Q | cut -d ' ' -f 1 | tr '\n' '|')
pacman -Ssq | egrep -v \'${installed}\'
答案2
这是一个具有 3 种不同方法的脚本,全部保留一行描述。它还允许您使用命令行参数进行搜索项
#!/bin/bash
#pacman -Ss "$@" | pcregrep -Mv '.*\[installed.*\n'
#pacman -Ss "$@" | sed -n -e '/\[installed/!p;: m' -e '//{' -e '$!{' -e 'n;b m' -e '}' -e'}'
pacman -Ss "$@" | awk '/\[installed/ { getline; next } 1'
例子:
pacman-search-exclude-installed.sh search terms
我的研究:
答案3
扩展 @thomas 的答案,这里有一些现成的函数,您可以获取并使用它们来实现 OP 问题
pmig () {
pacman -Q | grep $1 | cut -d ' ' -f 1
}
pmrg () {
pacman -Ssq | grep $1
}
pmnig () {
local installed="|$(pmig $1 | tr '\n' '|')"
pmrg $1 | grep -E -v \'${installed}\'
}
pmnigv () {
pacman -Ss $1 | grep -v "$(pacman -Ss $1 | grep "\[installed\]" -A1 )" | grep -v "\[installed\]"
}
然后尝试一下。
echo "==installed =="; pmig disk; echo "==in repos=="; pmrg disk; echo "===in repos but not installed==="; pmnig disk
结果是
==installed ==
gnome-disk-utility
gptfdisk
udiskie
udisks2
==in repos==
gnome-disk-utility
gptfdisk
plasma-disks
testdisk
udisks2
xfce4-diskperf-plugin
deepin-diskmanager
diskonaut
diskus
haskell-disk-free-space
kdiskmark
udiskie
udisks2-qt5
xdiskusage
yubikey-full-disk-encryption
===in repos but not installed===
plasma-disks
testdisk
xfce4-diskperf-plugin
deepin-diskmanager
diskonaut
diskus
haskell-disk-free-space
kdiskmark
xdiskusage
yubikey-full-disk-encryption
pmnigv 是详细版本
pmigv disk
extra/cdrdao 1.2.5-1
Records audio/data CD-Rs in disk-at-once (DAO) mode
extra/filelight 22.12.2-1 (kde-applications kde-utilities)
View disk usage information
extra/kdf 22.12.2-1 (kde-applications kde-utilities)
View Disk Usage
extra/libisofs 1.5.4-1
Library to pack up hard disk files and directories into a ISO 9660 disk image
extra/mtools 1:4.0.42-1
A collection of utilities to access MS-DOS disks
extra/partitionmanager 22.12.2-1 (kde-applications kde-system)
A KDE utility that allows you to manage disks, partitions, and file systems
extra/plasma-disks 5.26.5-1 (plasma)
Monitors S.M.A.R.T. capable devices for imminent failure
extra/qemu-img 7.2.0-3
QEMU tooling for manipulating disk images
....