Arch Cheat Sheet
Table of contents
Finding things
If you want to find something, there are several classes of objects that you can start with. Click on the link describing what you already have.
- Packages
These are the archlinux packages. They have a name.
- Package files
These are the
name-version-arch.pkg.tar.xz
files that contain a package. The first part of the file name is usually the package name. - Sources
A git source tree containing a PKGBUILD file.
- Installed Files
Any file that was installed and is part of an Arch package.
- Other files
Files that are not yet installed.
- Some keyword
If you look for a packages related to some keyword.
Packages
When looking for information, you normally first want to find the package name.
Here is how to list all packages that are installed:
pacman -Q
The package names are listed in the first column. The second column is the version.
If the package name is already known, one can get the installed version for a single package by running:
dpkg -Q name
Options that can be added to Q are:
- c : View the ChangeLog of a package if it exists.
- d : Restrict or filter output to packages installed as dependencies. This option can be combined with -t for listing real orphans - packages that were installed as dependencies but are no longer required by any installed package.
- e : Restrict or filter output to explicitly installed packages. This option can be combined with -t to list explicitly installed packages that are not required by any other package.
- g : Display all packages that are members of a named group. If a name is not specified, list all grouped packages.
- i : Display information on a given package. The -p option can be used if querying a package file instead of the local database. Passing two --info or -i flags will also display the list of backup files and their modification states.
- k : Check that all files owned by the given package(s) are present on the system. Specifying this option twice will perform more detailed file checking (including permissions, file sizes, and modification times) for packages that contain the needed mtree file.
- l : List all files owned by a given package.
- m : Restrict or filter output to packages that were not found in the sync database(s). Typically these are packages that were downloaded manually and installed with --upgrade.
- n : Restrict or filter output to packages that are found in the sync database(s). This is the inverse filter of --foreign.
- p : Signifies that the package supplied on the command line is a file and not an entry in the database.
- t : Restrict or filter output to print only packages neither required nor optionally required by any currently installed package. Specify this option twice to include packages which are optionally, but not directly, required by another package.
- u : Restrict or filter output to packages that are out-of-date on the local system. Only package versions are used to find outdated packages; replacements are not checked here. This option works best if the sync database is refreshed using -Sy.
Package files
These are name-version-arch.pkg.tar.xz
files that contain a package. The first part of the file name up till the first dash
is usually the package name.
Information about a package file can be obtained with the command:
pacman -Qi -p name-version-arch.pkg.tar.xz
This should extract the name of this package:
pacman -Qi -p package.pkg.tar.xz | grep '^Name *: ' | sed -e 's/Name *: //'
Sources
Sources are normally not installed. You can only install
them if you know the package name. When checking out the
git repository of an arch package, a file named PKGBUILD
is downloaded that will contain the name of the package
in its content (after the pkgname=
keyword).
Installed files
If you have a file /path/filename
installed, and you
want to know what package it belongs to (if any), then issue the
following command:
pacman -Qo /path/filename
This will print /path/filename is owned by name version
.
The path can be relative or absolute, and one or more files can be specified.
To search for regular expressions matching package names or descriptions (not installed files)
one can use: pacman -Qs <regexp>
. When including multiple search terms,
only packages with descriptions matching ALL of those terms are returned.
The command can therefore also used to search in a fuzzy way for packages
that have files installed matching the given pattern. It does however not
find/return extra files created by maintainer scripts, nor will it list
alternatives. You can therefore not conclude that it is safe to delete
a file if pacman -Qs
doesn't return any packages.
Other files
In order to find packages that contain file patterns that you do not
have installed, you need pacman -F
You need to regularly synchronize its database by running,
sudo pacman -Fy
Then, search for the filename using,
pacman -F /path/filenameor
pacman -Fx reg.exp
will give you a list of packages containing files matching reg.exp.
Note that it will NOT list manually installed packages (aka, from AUR)!
For installed files you should use pacman -Qo path
anyway.
Some keyword
To search each package in the sync databases for names or descriptions that match reg.exp, do
pacman -Ss reg.exp
When you include multiple search terms, only packages with descriptions matching ALL of those terms will be returned.
Queries
Now you have the package name, you can query the package database about it.
Contents
To print a list of all installed files (again excluding extra files as generated by maintainer script or alternatives), issue the command:
pacman -Ql name
You can also use this command to find out if a package with that
exact name is installed at all (or use just pacman -Q name
.
Or, if you have a package file that isn't installed yet, you can list its contents with
pacman -Qlp package.tar.xz
Version
To print the version of of an installed package, type
pacman -Q name
Everything
More information about an installed package can be obtained with the command:
pacman -Qi name
Or, if the package isn't installed yet
pacman -Qip package.pkg.tar.xz
Customizing packages
Getting the source
To work with Archlinux source packages, do as root:
pacman ... build essentials?
Often, a single source package generates multiple binary packages.
In order to find the name of the source that belongs to some package,
use pacman ???
. For example,
pacman -??? name
should print the source name of the package.
This name can then be used to download the sources with the command:
??? name
Building from source
In order to build a package, execute once as root: