LLI Wiki — My Digital Knowledge Base

Query packages with apt and dpkg (Debian)

apt, apt-cache and dpkg commands to list, search, describe and locate Debian packages.

The tools apt, apt-cache and dpkg show which packages are installed, where they come from, which files they provide and which dependencies they have.

Installed packages

sudo apt list --installed
sudo dpkg-query -l
sudo dpkg-query -f '${binary:Package}\n' -W | wc -l
dpkg -l '*tor*'
dpkg -l tor

The last wc -l command counts the installed packages.

Installed packages from a given repository

aptitude search "?origin (docker) ?installed"

Search for a package

apt-cache search apache
apt-cache policy tor
apt-cache show tor
apt-cache showpkg lightdm

apt-cache policy shows the installed and candidate versions and the repositories that provide them.

Repository a package comes from

apt-cache madison nom_du_paquet
find /etc/apt -type f -name '*.list*' -exec bash -c 'echo -e "\n$1\n"; nl -ba "$1"' _ '{}' \;
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/*

Dependencies

apt-cache depends tor
apt-rdepends tor

apt-rdepends is not installed by default.

Files of a package and owner of a file

dpkg -L tor
dpkg -S /bin/netstat

dpkg -L lists the files of an installed package. dpkg -S reports which package owns a file.

Simulate an installation from another version

sudo apt-cache policy vim
sudo apt-get install -t unstable vim -s | more
sudo apt-get install vim=2:8.0.0003-1 -s

The -s option simulates the installation without changing anything.

Mastodon LLIMastodon SocialFosstodon