How to use the command dpkg-query (with examples)
The dpkg-query
command is a tool that provides information about installed packages on a Debian-based system. It can be used to list installed packages, search for packages that own specific files, show information about a package, and more.
Use case 1: List all installed packages
Code:
dpkg-query --list
Motivation: You might want to see a comprehensive list of all the packages currently installed on your system. This can be useful for various purposes, such as checking for package conflicts or ensuring that all necessary software is present.
Explanation:
The --list
option is used to instruct dpkg-query
to list all installed packages without any filtering.
Example output:
ii accountsservice 0.6.55-0ubuntu12 amd64 query and manipulate user account information
ii acl 2.3.1-1 amd64 access control list - utilities
ii acpid 1:2.0.32-2ubuntu9 amd64 Advanced Configuration and Power Interface event daemon
...
Use case 2: List installed packages matching a pattern
Code:
dpkg-query --list 'libc6*'
Motivation: If you want to find installed packages based on a specific pattern or wildcard, you can use this command. It allows you to filter the list of installed packages and narrow down the results based on your criteria.
Explanation:
In this example, we are using the --list
option again to list packages. However, this time we provide a pattern libc6*
as an argument. The pattern libc6*
matches package names that start with “libc6”. The *
acts as a wildcard, allowing any characters to follow.
Example output:
ii libc6:amd64 2.31-0ubuntu9.14 amd64 GNU C Library: Shared libraries
ii libc6-dbg:amd64 2.31-0ubuntu9.14 amd64 GNU C Library: detached debugging symbols
ii libc6-dev:amd64 2.31-0ubuntu9.14 amd64 GNU C Library: Development Libraries and Header Files
Use case 3: List all files installed by a package
Code:
dpkg-query --listfiles libc6
Motivation: You might want to know all the files that are installed by a particular package. This command allows you to retrieve a list of files that belong to a specific package.
Explanation:
The --listfiles
option is used to provide information about the files installed by a package. In this example, we specify libc6
as the package name.
Example output:
/.
/etc
/etc/ld.so.conf.d
/etc/ld.so.conf.d/x86_64-linux-gnu.conf
...
/usr/bin/ldd
/usr/lib
/usr/lib/x86_64-linux-gnu
...
Use case 4: Show information about a package
Code:
dpkg-query --status libc6
Motivation: If you need to gather more detailed information about a particular package, you can use this command. It provides information such as the package name, version, architecture, and more.
Explanation:
The --status
option is used to show information about a package. In this example, we provide libc6
as the package name.
Example output:
Package: libc6
Status: install ok installed
Priority: required
Section: libs
Installed-Size: 22 ...
...
Use case 5: Search for packages that own files matching a pattern
Code:
dpkg-query --search /etc/ld.so.conf.d
Motivation: If you want to find which package owns a specific file or files matching a pattern, you can utilize this command. It helps you identify the package responsible for a particular file or set of files.
Explanation:
The --search
option is used to search for packages that own files matching a given pattern. In this example, we provide /etc/ld.so.conf.d
as the pattern to search for.
Example output:
libc6:amd64: /etc/ld.so.conf.d/x86_64-linux-gnu.conf
Conclusion:
The dpkg-query
command is a versatile tool that provides useful information about installed packages on a Debian-based system. By utilizing its various options, you can easily list installed packages, search for packages owning specific files, show detailed package information, and more. This command is invaluable for managing and troubleshooting packages on your system.