brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: apt-cache search -n finds a package by its name, without the noise

Apt
~/tips/tip-apt-cache-search-names-only

apt-cache search --names-only zstd

Searches package names only, so results don't drown in description matches.

A plain apt search ssl returns hundreds of results, because it also matches every description that mentions SSL. When you roughly know the name, search names only.

The search term is a regular expression:

apt-cache search --names-only zstd
apt-cache search --names-only '^php8.3-'
apt-cache search --names-only 'fonts-.*mono'

The first finds everything with zstd in its name, like zstd and libzstd1. The second uses ^ to list all PHP 8.3 extensions, which is a quick way to see whether the one you need is packaged. The third shows how a pattern in the middle narrows things down.

Each result is a name and the short description, one per line, so it pipes well into grep or wc -l.

The short form is -n. I’d stick with apt-cache here rather than apt search, because its output format is stable and safe to use in scripts.

It only searches what your package lists contain. If a package lives in a repository you haven’t added, or the lists are out of date, you won’t find it, so run sudo apt update first on a fresh system. When you’re looking for the package that ships a particular file rather than a name, apt-file is the tool for that.

Further reading: apt-cache(8) manual page

More Apt tips sudo apt-mark minimize-manual apt list '~c' grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -o Dpkg::Options::="–force-confold" upgrade sudo apt-get -d -y full-upgrade All Apt tips (42) All topics

Link