# man > apt-patterns(7)

---
type: CommandReference
command: apt-patterns
mode: man
section: 7
source: man-pages
---

## Quick Reference
- `apt remove '?garbage'` — Remove automatically installed packages no longer needed (same as autoremove)
- `apt purge '?config-files'` — Purge packages with only residual configuration files left
- `apt list '~i !~M (~slibs|~sperl|~spython)'` — List manually installed packages in sections libs, perl, python
- `apt search '?installed ?name(foo)'` — Search installed packages with name matching "foo"
- `apt search '?upgradable'` — List packages that have a newer candidate
- `apt search '?architecture(amd64) ?installed'` — List installed amd64 packages
- `apt search '?obsolete'` — List packages no longer in repositories
- `apt search '?essential ?installed'` — List installed essential packages

## Name
apt-patterns — Syntax and semantics of apt search patterns

## Synopsis
Patterns are used with `apt` commands (e.g., `apt search`, `apt list`, `apt remove`) to filter packages.  
Syntax: `apt command 'PATTERN'`

## Patterns

### Logic 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, used to work around precedence.

### Narrowing Patterns
- `?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 (restricts logic to a single version).
- `?narrow(PATTERN...)` — Selects any version matching all PATTERNs; short for `?any-version(?and(PATTERN...))`.

### Package Patterns
- `?architecture(WILDCARD), ~rWILDCARD` — Selects packages matching the specified architecture (wildcards allowed).
- `?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 residual configuration files left.
- `?essential, ~E` — Selects packages with Essential: yes.
- `?exact-name(NAME)` — Selects packages with the exact specified name.
- `?garbage, ~g` — Selects packages that can be removed automatically.
- `?installed, ~i` — Selects currently installed packages.
- `?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; i.e., packages without a version.

### Version Patterns
- `?archive(REGEX), ~AREGEX` — Selects versions from the archive matching regex (value after a= in `apt-cache policy`).
- `?codename(REGEX)` — Selects versions from the codename matching regex (value after n= in `apt-cache policy`).
- `?origin(REGEX), ~OREGEX` — Selects versions from the origin matching regex (value after o= in `apt-cache policy`).
- `?section(REGEX), ~sREGEX` — Selects versions where the section matches regex.
- `?source-package(REGEX), ~eREGEX` — Selects versions where the source package name matches regex.
- `?source-version(REGEX)` — Selects versions where the source package version matches regex.
- `?version(REGEX), ~VREGEX` — Selects versions where the version string matches regex.
- `?priority(NAME), ~pNAME` — Selects versions where the Priority string equals the given name (e.g., required, important).

### Package Relationship Patterns
- `?depends(PATTERN), ~DPATTERN` — Selects versions depending on packages matching PATTERN.  
  Also: `?pre-depends`, `?suggests`, `?conflicts`, `?replaces`, `?obsoletes`, `?breaks`, `?enhances` with corresponding aliases (`~DPre-Depends:PATTERN`, etc.).
- `?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 above (e.g., `depends`, `conflicts`).

## Examples
shell
# Remove all automatically installed packages no longer needed
apt remove ?garbage

# Purge packages that only have configuration files left
apt purge ?config-files

# List manually installed packages in sections matching libs, perl, or python
apt list '~i !~M (~slibs|~sperl|~spython)'
## See Also
- [apt-get(8)](http://localhost/phpMan.php/man/apt-get/8/markdown)
- [apt(8)](http://localhost/phpMan.php/man/apt/8/markdown)