Package Manager Cheat Sheet
This Package Manager cheat sheet is just a collection of some useful commands that I tend to forget from time to time.
Table of Contents
dnf / yum
# list all enabled repositories
dnf repolist
# disable repositories
dnf config-manager --set-disabled pgdg*
# list the files contained in a package
dnf repoquery -l postgresql
# list all installed packages
dnf list installed
# list all available packages from a repo
dnf repoquery --repo pgAdmin4
dnf repo-pkgs pgAdmin4 list
# search for a package
dnf search resource-agents
# which (installed or uninstalled) package provides a file
dnf provides */createrepo
# disable subscription manager
sed -i s/^enabled=1/enabled=0/ /etc/dnf/plugins/subscription-manager.conf
# list available and installed package groups
dnf group list
rpm
# list all installed packages
rpm -qa
# which package provided a installed file
rpm -qf /usr/pgsql-17/bin/postgres
# list all files contained in a package
rpm -ql postgresql17-server
# locate the path of a file provided by any package
rpm -qal | grep pg_config
# list all installed gpg keys
rpm -qa --qf 'gpg-pubkey-%{VERSION}-%{RELEASE} %{SUMMARY}\n' gpg-pubkey*
# remove a gpg key
rpm -e gpg-pubkey-10458545-64e78669
# uninstall a package
rpm -e nano-2.9.8-1.el8.x86_64
apt / dpkg
# list installed packages
dpkg -l
# search available packages
apt-cache search zabbix-agent2
# show packages ordered by install date
find /var/lib/dpkg/info -name "*.list" -printf "%TY-%Tm-%Td %f\n" | sed 's/\.list$//; s/:.*$//' | awk '{print $2, $1}' | sort -k1 | join -1 1 -2 1 -o '1.2 1.1 2.2' - <(dpkg-query -W -f '${Package}\t${Status}\t${Installed-Size}\n' | awk -F'\t' '$2 ~ /install ok installed/ {print $1, $3}' | sort) | awk '{printf "%s %-35s %8.2f MB\n", $1, $2, $3/1024}' | sort -k1
# show packages ordered by size
find /var/lib/dpkg/info -name "*.list" -printf "%TY-%Tm-%Td %f\n" | sed 's/\.list$//; s/:.*$//' | awk '{print $2, $1}' | sort -k1 | join -1 1 -2 1 -o '1.2 1.1 2.2' - <(dpkg-query -W -f '${Package}\t${Status}\t${Installed-Size}\n' | awk -F'\t' '$2 ~ /install ok installed/ {print $1, $3}' | sort) | awk '{print $1, $2, $3}' | sort -k3n | awk '{printf "%s %-35s %8.2f MB\n", $1, $2, $3/1024}'
# purge (completely remove) packages that are uninstalled, but config files are still present
to check: dpkg -l | awk '/^rc/ { print $2 }'
to remove: sudo apt purge $(dpkg -l | awk '/^rc/ { print $2 }')

Leave a Reply