apt-patterns โ Syntax and semantics of apt search patterns
| Use Case | Command | Description |
|---|---|---|
| ๐ Search by package name | apt list '?name(REGEX)' | Find packages matching a regular expression |
| ๐๏ธ Remove automatically installed & orphaned | apt remove ?garbage | Same as apt autoremove |
| ๐งน Purge config-file leftovers | apt purge ?config-files | Remove packages with only residual config |
| ๐ List manually installed packages by section | apt list '~i !~M (~slibs|~sperl|~spython)' | Filter by section regex |
| โฌ๏ธ Find upgradable packages | apt list ?upgradable | Packages with newer candidates |
| ๐ฃ Find broken dependencies | apt list ?broken | Packages with broken dependency chains |
| ๐๏ธ Filter by architecture | apt list '?architecture(amd64)' | Using wildcards supported |
| ๐ Combined logical patterns | apt list '?and(?installed,?upgradable)' | AND/OR/NOT nesting |
Starting with version 2.0, APT provides support for patterns, which can be used to query the apt cache for packages.
These patterns provide the basic means to combine other patterns into more complex expressions, as well as ?true and ?false patterns.
?and(PATTERN, PATTERN, ...), PATTERN PATTERN ... โ Selects objects where all specified patterns match.?false, ~F โ Selects nothing.?not(PATTERN), !PATTERN โ Selects objects where PATTERN does not match.?or(PATTERN, PATTERN, ...), PATTERN | PATTERN | ... โ Selects objects where at least one of the specified patterns match.?true, ~T โ Selects all objects.(PATTERN) โ Selects the same as PATTERN, can be used to work around precedence. Example: (~ramd64|~ri386)~nfoo?all-versions(PATTERN) โ Selects packages where all versions match PATTERN. When matching versions instead, same as PATTERN.?any-version(PATTERN) โ Selects any version where the pattern matches on the version.For example, while ?and(?version(1),?version(2)) matches a package which has one version containing 1 and one version containing 2, ?any-version(?and(?version(1),?version(2))) restricts the ?and to act on the same version.
?narrow(PATTERN...) โ Selects any version matching all PATTERNs, short for ?any-version(?and(PATTERN...)).These patterns select specific packages.
?architecture(WILDCARD), ~rWILDCARD โ ๐๏ธ Selects packages matching the specified architecture, which may contain wildcards using any.?automatic, ~M โ ๐ค Selects packages that were installed automatically.?broken, ~b โ ๐ฅ Selects packages that have broken dependencies.?config-files, ~c โ ๐๏ธ Selects packages that are not fully installed, but have solely residual configuration files left.?essential, ~E โ โญ Selects packages that have Essential: yes set in their control file.?exact-name(NAME) โ ๐ฏ Selects packages with the exact specified name.?garbage, ~g โ ๐๏ธ Selects packages that can be removed automatically.?installed, ~i โ โ
Selects packages that are currently installed.?name(REGEX), ~nREGEX โ ๐ Selects packages where the name matches the given regular expression.?obsolete, ~o โ โณ Selects packages that no longer exist in repositories.?upgradable, ~U โ โฌ๏ธ Selects packages that can be upgraded (have a newer candidate).?virtual, ~v โ ๐ป Selects all virtual packages; that is packages without a version. These exist when they are referenced somewhere in the archive, for example because something depends on that name.These patterns select specific versions of a package.
?archive(REGEX), ~AREGEX โ ๐ฆ Selects versions that come from the archive matching the specified regular expression. Archive means the values after a= in apt-cache policy.?codename(REGEX) โ ๐ท๏ธ Selects versions that come from the codename matching the specified regular expression. Codename means the values after n= in apt-cache policy.?origin(REGEX), ~OREGEX โ ๐ Selects versions that come from the origin matching the specified regular expression. Origin means the values after o= in apt-cache policy.?section(REGEX), ~sREGEX โ ๐ Selects versions where the section matches the specified regular expression.?source-package(REGEX), ~eREGEX โ ๐ Selects versions where the source package name matches the specified regular expression.?source-version(REGEX) โ ๐ Selects versions where the source package version matches the specified regular expression.?version(REGEX), ~VREGEX โ ๐ Selects versions where the version string matches the specified regular expression.?priority(NAME), ~pNAME โ ๐
Selects versions where the Priority string equals the given name.These patterns match specific package versions that depend/conflict with some other packages.
?depends(PATTERN), ~DPATTERN โ ๐ depends on?pre-depends(PATTERN), ~DPre-Depends:PATTERN โ ๐ pre-depends on?suggests(PATTERN), ~DSuggests:PATTERN โ ๐ก suggests?conflicts(PATTERN), ~DConflicts:PATTERN โ โก conflicts with?replaces(PATTERN), ~DReplaces:PATTERN โ ๐ replaces?obsoletes(PATTERN), ~DObsoletes:PATTERN โ ๐๏ธ obsoletes?breaks(PATTERN), ~DBreaks:PATTERN โ ๐ breaks?enhances(PATTERN), ~DEnhances:PATTERN โ โจ enhances?reverse-depType(PATTERN), ~RDepType:PATTERN โ ๐ Opposite of ?depends and friends โ selects all packages that have reverse-dependencies (versions) matching PATTERN.depType is one of the dependency types such as depends, so that we don't have to repeat the entire list from the first paragraph here.
apt autoremove):apt remove ?garbage
apt purge ?config-files
libs, perl, or python:apt list '~i !~M (~slibs|~sperl|~spython)'
Patterns in apt are heavily inspired by patterns in aptitude, but with some tweaks:
?foo(bar) could mean ?and(?foo,bar) if foo does not take an argument. In APT, this will cause an error.~ is not supported.?narrow accepts infinite arguments.foo cannot be used as a shortform for ?name(foo), as this can cause typos to go unnoticed: Consider ?and(...,~poptional): this requires the package to have required priority, but if you do not type the ~, it would require the package name to contain poptional.(...) or writing ?or(A,B) as A|B are not supported. We do not believe that the use of | is that common, and the grouping is not necessary without it.~D and related operators need to be specified in the canonical case.APT bug page[1]. If you wish to report a bug in APT, please see /usr/share/doc/debian/bug-reporting.txt or the reportbug(1) command.
APT was written by the APT team <apt@packages.org>.
APT 2.4.14 ยท 26 December 2021 ยท APT-PATTERNS(7)
Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-09 09:01 @2600:1f28:365:80b0:50b3:453e:ff52:20f7
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format