OFFSET偏移
← All articlesOFFSET / FIELD NOTESNO. 061

Common Pacman commands and how to remember their flags

Use the S, Q, R, and U operation groups to distinguish repository queries, local queries, removal, and local package installation.

English translation · Code and commands follow the Chinese original.

IN THESE READING PATHSArch Linux ↗
About 3 min readStart reading

Two-Level Syntax and Common Flags#

The easiest way to remember pacman is as "two levels of syntax":

pacman -<大类><小参数>

At the first level, learn the four most common operation groups:

  • S = Sync: synchronize with repositories / install software
  • Q = Query: query software installed locally
  • R = Remove: uninstall
  • U = Upgrade: install a local package file

These are the essential operations.

Command Meaning Memory aid
pacman -S 包名 Install software S = Sync/install
pacman -Syu Upgrade the entire system y = refresh, u = upgrade
pacman -Ss 关键词 Search repositories The second s = search
pacman -Si 包名 View details of a repository package i = info
pacman -Qs 关键词 Search installed software Q = local Query + s = search
pacman -Qi 包名 View details of an installed package i = info
pacman -Ql 包名 List the files installed by a package l = list
pacman -Qo /路径/文件 Find which package owns a file o = owner
pacman -R 包名 Uninstall R = Remove
pacman -Rs 包名 Uninstall along with dependencies that are no longer needed s = recursive deps
pacman -Rns 包名 Uninstall along with dependencies that are no longer needed, without saving managed configuration files as .pacsave n = nosave
pacman -U xxx.pkg.tar.zst Install a local package U = Upgrade file
pacman -Sc Clean old cached packages c = clean

Your most frequent everyday commands can be reduced to:

sudo pacman -Syu
sudo pacman -S foo
pacman -Ss foo
pacman -Qs foo
pacman -Qi foo
pacman -Ql foo
pacman -Qo /usr/bin/foo
sudo pacman -Rns foo

The most important distinction to understand is between S and Q:

-S* → 问“仓库里有什么”
-Q* → 问“我电脑上已经有什么”

So:

pacman -Ss firefox

= Search remote repositories for firefox.

pacman -Qs firefox

= Search the firefox-related packages already installed locally.

A Few Easily Confused Commands

pacman -Sy

This only refreshes the database, without upgrading packages. Generally, avoid doing this by itself on Arch, as it can cause a partial upgrade.

Normally, use:

sudo pacman -Syu

One way to memorize it is:

S = Sync
y = refresh repository database
u = upgrade installed packages

In other words:

同步 → 刷新数据库 → 升级

-Rns is also worth committing to muscle memory:

R = Remove
n = nosave,不生成受管理配置的 .pacsave 备份
s = 顺便删无用依赖

Before uninstalling, confirm that you no longer need the software and decide whether to retain .pacsave configuration backups:

sudo pacman -Rns foo

Orphaned Dependencies and File Checks#

The following commands are useful for troubleshooting:

pacman -Qdt

Find orphaned dependencies. Remember it as:

Q = query
d = dependency
t = unrequired

Inspect the query results first. Packages you still need should be marked as explicitly installed. For removal, specify only package names you have confirmed are no longer needed:

sudo pacman -Rns <CONFIRMED_ORPHAN_PACKAGE>

And:

pacman -Qk foo

Check whether any files installed by a package are missing; k = check.

pacman -Qkk foo

Perform a more detailed check.

Flag Compatibility in AUR Helpers#

If you use paru, most pacman query and installation flags work unchanged:

paru -S foo
paru -Ss foo
paru -Qs foo
paru -Syu

The simplest mental map is:

pacman
├── S  仓库 / 安装
│   ├── s search
│   ├── i info
│   └── yu 更新
├── Q  本机查询
│   ├── s search
│   ├── i info
│   ├── l list files
│   └── o owner
├── R  卸载
│   └── ns 干净卸载
└── U  本地 pkg.tar.zst

S / Q / R / U provide a starting point for memorization. For removal and cache cleanup, still review the confirmation list and the current manual. -n does not erase all settings in a user's home directory.

References & further reading

  1. ArchWiki: Pacman ↗
  2. pacman(8) ↗

Adapted from technical notes. Examples use generic names.

Continue along a reading path

Arch Linux

  1. 01Arch Linux philosophy and installation planning
  2. 02Kernel management, systemd-boot, and UKIs
  3. 03Pacman hooks, the AUR, and build security
  4. 04Btrfs subvolume layouts and Snapper snapshots
  5. 05Hardening with LUKS2, Secure Boot, and TPM2
  6. 06Performance choices and an everyday maintenance checklist
  7. 07Common Pacman commands and how to remember their flags
  8. 08Diagnosing slow Pacman downloads and choosing mirrors
  9. 09informant: Arch news and Pacman hooks
  10. 10Arch Linux with Btrfs: manual installation and archinstall
  11. 11Configuring GNOME, input methods, and snapshots
  12. 12GNOME laptop management and desktop customization
  13. 13KVM, GPU passthrough, and gaming on Arch Linux
  14. 14Swap, kernels, and troubleshooting on an Arch desktop
CONTINUE READING / NEXT ARTICLEDiagnosing slow Pacman downloads and choosing mirrors

Locate download bottlenecks step by step through networking, mirror status, and parallel downloads.