search for only installed packages using apt

42,617

Solution 1

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.

Solution 2

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

or:

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

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

Solution 3

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.

Share:
42,617

Related videos on Youtube

Exostor
Author by

Exostor

System engineer/administrator at Linköping University, Linköping, Sweden Building Linux servers, virtualization on XEN, Rails applications and misc hacking in mostly Python. Have my own 19" 1.8m high serverrack in my garage.

Updated on September 18, 2022

Comments

  • Exostor
    Exostor over 1 year

    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
    Exostor over 7 years
    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.
  • VanagaS
    VanagaS over 7 years
    Instead of globbing, -a could be used to list all matching packages
  • Exostor
    Exostor over 7 years
    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.
  • ysth
    ysth over 5 years
    @Exostor what does -a actually do?
  • Exostor
    Exostor over 5 years
    @ysth Lists all versions of the package. Without -a it only lists the latest release.
  • JoeManiaci
    JoeManiaci over 4 years
    Out of everything above this is the only thing that worked for me on Mint 18.3