Arch Cheat Sheet

Carlo Wood, Januari 2021

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

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:

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/filename
or
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:

Creating a patch

Adding a patch to an arch package

Creating a source package

Setting up a repository

Pinning the packages of your local repository