4

What flags can one use with pacman -S to show only those packages, that aren't yet installed?

Will accept shell script if it can't be done by design. Thx.

3 Answers 3

4

After first try was the inverse answer, thanks Jeff Schaller. Here's a little script that filters out installed packages and only displays not installed packages.

#!/bin/sh installed=$(pacman -Q | cut -d ' ' -f 1 | tr '\n' '|') pacman -Ssq | egrep -v \'${installed}\' 
4
  • "... aren't yet installed" Commented Feb 26, 2017 at 11:14
  • PLUS: Use pacman -Ssq | egrep -v \'${installed}\' | egrep -i '<YOUR_PACKAGE_NAME_OR_PART>' to search only among uninstalled packages. NOTE: q flag excludes description. Ref.: archlinux.org/pacman/pacman.8.html#_query_options_a_id_qo_a Commented Feb 13, 2018 at 18:43
  • 1
    As egrep is deprecated, I used pacman -Ssq | grep -E -v \'${installed}\' - and to search you just add it to the first part, no additional piping needed: pacman -Ssq pkgname | grep -E -v \'${installed}\' (after setting the installed variable). To pass this on to pacman for installation, you to add another pipe: pacman -Ssq xfce4 | grep -E -v \'${installed}\' | pacman -S - Commented Mar 29, 2024 at 15:27
  • This can have false positives/negatives for example with the r package which will match against every package containing an r. installed="|^"$(pacman -Q | cut -d ' ' -f 1 | tr '\n' '*' | sed 's/\*/$|^/g') seems to work for me. Commented Jun 8, 2024 at 23:03
1

here is a script with 3 different methods, all keeping the one line description. also it lets you do search terms with command line arguments

#!/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' 

example:

pacman-search-exclude-installed.sh search terms 

my research:

How to grep -v and also exclude the next line after the match?

How to `grep -v` and also exclude 'n' lines after the match?

0

expanding on @thomas answer here are some ready to go functions you can source and use to achieve OPs question

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\]" } 

then trying out.

echo "==installed =="; pmig disk; echo "==in repos=="; pmrg disk; echo "===in repos but not installed==="; pmnig disk

results in

==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 

an pmnigv is a verbose version

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 .... 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.