
expac: A practical data extraction tool for pacman databases
expac: A practical data extraction tool for pacman databases
Introduction
expac is a lightweight, printf-like querying tool for ALPM databases (the same databases pacman uses). It shines when you want clean, machine-friendly output for scripts or just to inspect package metadata quickly.
Quick start: what you can get with expac
- List the dependencies of a package
- List optional dependencies
- Show download sizes in human-readable form
- Filter packages that are upgradable and show sizes
- List explicitly installed packages with their optional dependencies
Examples
- List the dependencies of a package
expac {{[-S|--sync]}} '%D' {{package}}
- List the optional dependencies of a package
expac {{[-S|--sync]}} "%o" {{package}}
- List the download size of packages in MiB (human-friendly)
expac {{[-S|--sync]}} {{[-H|--humansize]}} M '%k\t%n' {{package1 package2 ...}}
- List packages marked for upgrade with their download size
expac {{[-S|--sync]}} {{[-H|--humansize]}} M '%k\t%n' $(pacman -Qqu) | sort {{[-sh|--sort --human-numeric-sort]}}
- List explicitly-installed packages with their optional dependencies
expac {{[-d|--delim]}} '\n\n' {{[-l|listdelim]}} '\n\t' {{[-Q|--query]}} '%n\n\t%O' $(pacman -Qeq)
What the options mean (quick glossary)
- -S or —sync: use the sync databases (updates reflect in true metadata)
- -H or —humansize: format sizes in a readable unit (e.g., MiB)
- -d or —delim: customize the delimiter between records
- -l or —listdelim: customize the delimiter within a record
- -Q or —query: run a query expression (the format string)
Common use cases
- Get a quick view of a package’s dependencies
expac -S '%D' linux
- Show how much space a package would take to download (human-readable)
expac -S -H M '%k' linux
- Find all explicitly installed packages and their optional deps
expac -d '\n\n' -l '\n\t' -Q '%n\n\t%O' $(pacman -Qe)
Tips and pitfalls
- Cache freshness matters. If you see a note like the cache hasn’t been updated for a long time, run your package manager update first to ensure expac reads current data.
# If you see stale data, refresh databases (example)
sudo pacman -Sy
- Use -S/—sync with caution in scripts. It queries the database; if you want installed data only, you can omit sync to reduce network usage.
- Quoting matters. When using format strings with % characters, wrap them in quotes as shown in examples to avoid shell expansion issues.
Putting it together: a small script example
#!/usr/bin/env bash
# List all upgradeable packages with their download sizes in MiB
expac {{[-S|--sync]}} {{[-H|--humansize]}} M '%k\t%n' $(pacman -Qqu) | sort -h
Conclusion
expac is a simple, flexible way to extract package data from ALPM databases without parsing pacman output. Start with the basic queries above and adapt the format strings to fit your workflow.