3

I guess i is installed, but the others?

$ apt search * | sort -t' ' -k1 | cut -c1 | uniq
c
i
p
v
Erwann
  • 605
  • 1
  • 8
  • 18
  • 3
    Could you [edit] your question to show the output of `ls`, in the same directory you ran the `apt` command above? – Stephen Kitt Oct 29 '19 at 21:22
  • https://unix.stackexchange.com/a/73805/338177 – schrodingerscatcuriosity Oct 29 '19 at 21:45
  • @StephenKitt how would `ls` be relevant? I think it was from the directory created by `tar emacs-26.3.tar.xz`. – Erwann Oct 29 '19 at 21:52
  • So, based on @guillermochamorro answer my guess was completely wrong. Which leaves open the question: how to know search and check for installed at the same time? – Erwann Oct 29 '19 at 21:55
  • 3
    @Erwann it’s relevant because `apt search *` expands `*` with the names of the files in the current directory. – Stephen Kitt Oct 29 '19 at 22:43
  • It should have been `apt search .*` or `apt-cache search .*`. They return 108063 and 64639 lines respectively. – Erwann Oct 29 '19 at 23:40
  • 3
    @Erwann those would have had the same problem, expanding `.*`, unless you quoted them or escaped the `*`. But unlike `aptitude search` which the linked question refers to, `apt search` and `apt-cache` search output the package name first, so the first character in the line wouldn’t give you any information about the state of the package. – Stephen Kitt Oct 30 '19 at 09:35

1 Answers1

1

apt search’s output takes the form

package name/suites version architecture [state]
  description

so extracting the first column won’t give much useful information.

Addressing your updated question from your comment, “how to know search and check for installed at the same time?”, you can use

apt search $pattern | grep -A1 '\[.*installed.*\]'

This will show the installed packages matching $pattern; for example on my system

$ apt search evdev | grep -A1 '\[.*installed.*\]'

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

evemu-tools/stable,now 2.7.0-1 amd64 [installed,automatic]
  Linux Input Event Device Emulation Library - test tools
--
joystick/stable,now 1:1.6.1-1 amd64 [installed]
  set of testing and calibration tools for joysticks
--
libevdev-build-deps/now 1.6.0+dfsg-1 all [installed,local]
  build-dependencies for libevdev
--

etc.

The warning is irrelevant here; you can’t avoid it by using apt-cache instead because apt-cache doesn’t show all the information needed.

You can also use aptitude:

aptitude search '~i evdev`

will search for installed packages matching “evdev”.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • "so extracting the first column won’t give much useful information": that's a straw man since I had already acknowledged I had mistaken the first column for the state. Output of `apt search` on my platform/setup does not specify `[state]` in any column. So, this does not solve my question. – Erwann Nov 02 '19 at 07:19
  • Would you mind clarifying what platform you’re using? – Stephen Kitt Nov 02 '19 at 07:49
  • `$ uname -a; cat /etc/*-release | grep DISTRIB_DESCRIPTION Linux laptop 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux cat: /etc/upstream-releaseDISTRIB_DESCRIPTION="Linux Mint 19 Tara"` – Erwann Nov 02 '19 at 07:59
  • Try `aptitude` then, see my updated answer. – Stephen Kitt Nov 02 '19 at 08:53