34

Using aptitude I can make a search like:

aptitude search '~i bash'

This seems to be an aptitude specific regex. Is it possible to do the same thing using apt or apt-cache without additional commands?

apt search '~i bash'

is not working.

Exostor
  • 451
  • 1
  • 4
  • 7

3 Answers3

42

You can try:

apt list --installed bash

This will try to list the installed packages with the name bash

However, if you wanted to search for a particular file, use apt-file

The following command will list all the packages that have string bash within their name:

apt list -a --installed bash

As suggested by @Exostor apt list -a --installed bash is not always the case to list those packages that start with a particular string, instead use:

apt list -a --installed bash*

If globbing is what you're searching for, please upvote @Exostor comment below.

VanagaS
  • 744
  • 7
  • 6
  • 5
    Ah! but that will not do it, because it will not list bash-builtins, bash-doc etc.. But `apt list --installed bash*` is close enough for me. – Exostor Aug 31 '16 at 12:24
  • Instead of globbing, `-a` could be used to list all matching packages – VanagaS Sep 06 '16 at 06:26
  • 3
    Doesn't work for me. Ubuntu 16.04-machine: `apt list -a --installed bash` lists bash/xenial-updates and bash/xenial but `apt list --installed bash*` lists bash, bash-completion and bash-doc, which is the three bash-packages installed on the machine. – Exostor Sep 14 '16 at 14:14
  • @Exostor what does -a actually do? – ysth Aug 20 '18 at 21:48
  • 1
    @ysth Lists all versions of the package. Without -a it only lists the latest release. – Exostor Sep 12 '18 at 12:05
7

dpkg-query --list | grep '^.i\s*PKG'

or:

dpkg-query --list PKG\* | grep '^.i'

where PKG is the desired package name / a reg-ex.

elig
  • 561
  • 1
  • 6
  • 13
4

If anybody else is wondering how to go about doing this, I use the following method.

apt list --installed | grep [XYZ]

This method also shows different packages that are installed containing the string you were searching for. For example, if I'm searching for vlc, I'm shown many other packages which also have 'vlc' in their name. Here's input and output:

apt list --installed | grep vlc

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

browser-plugin-vlc/stable,now 2.0.6-4 amd64 [installed]
libvlc-bin/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
libvlc5/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
libvlccore8/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
phonon4qt5-backend-vlc/stable,now 0.9.0-2 amd64 [installed,automatic]
vlc/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-bin/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-data/stable,stable,stable,stable,now 2.2.7-1~deb9u1 all [installed]
vlc-l10n/stable,stable,stable,stable,now 2.2.7-1~deb9u1 all [installed]
vlc-plugin-base/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-notify/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-qt/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-samba/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-skins2/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-video-output/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-video-splitter/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]
vlc-plugin-visualization/stable,stable,now 2.2.7-1~deb9u1 amd64 [installed]

If it turns out you don't have the package installed, the command will simply exit.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Ev-
  • 619
  • 1
  • 5
  • 15