Managing .pacnew and .pacsave Files in Arch Linux
Understanding Pacnew and Pacsave Files
In Arch Linux, when upgrading packages using pacman -Syu, the package manager may create special backup files to prevent overwriting user-modified configurations. Understanding these files is essential for maintaining a stable system.
Pacnew Files
During package upgrades, pacman creates .pacnew files when it needs to install a new version of a configuration file that you have previously modified. This mechanism protects your customizations from being overwritten. You'll see a message like:
warning: /etc/pam.d/usermod installed as /etc/pam.d/usermod.pacnew
Pacsave Files
When removing or upgrading packages, pacman creates .pacsave files for configuration files that were previously backed up by the package database. A typical warning message looks like:
warning: /etc/pam.d/usermod saved as /etc/pam.d/usermod.pacsave
Locating .pac* Files
Pacman does not automatically handle these files—you must manage them manually. There are several methods to discover pending .pacnew or .pacsave files.
Using find Command
Search the /etc directory, which contains most system-wide configuration files:
$ find /etc -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null
/etc/locale.gen.pacnew
/etc/shadow.pacnew
/etc/pacman.conf.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/nftables.conf.pacnew
Using locate Database
For faster searching, update the database and use locate:
$ sudo updatedb
$ locate --existing --regex "\.pac(new|save)$"
/etc/locale.gen.pacnew
/etc/nftables.conf.pacnew
/etc/pacman.conf.pacnew
/etc/shadow.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
Using Pacman Logs
You can also search pacman's log file for historical records:
$ grep --extended-regexp "\.pac(new|save)" /var/log/pacman.log
...
[2020-06-25T04:58:54+0800] [ALPM] warning: /etc/pacman.d/mirrorlist installed as /etc/pacman.d/mirrorlist.pacnew
Managing Pacnew and Pacsave Files with pacdiff
The pacdiff tool from the pacman-contrib package provides a straightforward way to handle these files. It locates all .pacnew and .pacsave files and prompts you for action on each one. By default, it uses vimdiff, but you can specify alternative diff tools.
Listing Pending Files
To see all pending files without processing them:
$ pacdiff -l -o
/etc/locale.gen.pacnew
/etc/nftables.conf.pacnew
/etc/pacman.conf.pacnew
/etc/shadow.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
Using a Visual Merge Tool
To process files in /etc using meld:
$ sudo DIFFPROG=meld DIFFSEARCHPATH="/etc" pacdiff
When invoked, you'll see prompts for each file:
==> pacnew file found for /etc/shadow
:: (V)iew, (S)kip, (R)emove pacnew, (O)verwrite with pacnew, (Q)uit: [v/s/r/o/q]
Interactive Options
- (v) - View the differences in your merge tool (e.g., meld), allowing you to manually synchronize changes between files. After saving your changes in the merge tool, return to the prompt.
- (r) - Remove the .pac* file after you've successfully merged the changes manually.
- (o) - Overwrite the existing configuration with the new .pac* file if you haven't made significant customizations.
- (s) - Skip this file and address it later.
pacdiff Command Reference
pacman-contrib Utilities Overview
The pacman-contrib package includes several helpful utilities for Arch Linux system management:
Usage Examples
$ paclog-pkglist |wc -l
779
$ sudo paccache -rk1
==> finished: 16 packages removed (disk space saved: 230.82 MiB)
$ pacscripts chromium
post_upgrade() {
if (($(vercmp $2 42.0.2311.90-1) < 0)); then
...
fi
}
# vim:set ts=2 sw=2 et:
$ checkupdates
ca-certificates-mozilla 3.53.1-1 -> 3.54-1
curl 7.70.0-1 -> 7.71.0-1
gtk-update-icon-cache 1:3.24.20-1 -> 1:3.24.21-1
gtk3 1:3.24.20-1 -> 1:3.24.21-1
imagemagick 7.0.10.21-1 -> 7.0.10.22-1
libfontenc 1.1.4-2 -> 1.1.4-3
libglvnd 1.3.1-1 -> 1.3.2-1
libwacom 1.3-1 -> 1.4-2
nspr 4.25-1 -> 4.26-1
nss 3.53.1-1 -> 3.54-1
perl-http-message 6.24-2 -> 6.25-1
unrar 1:5.9.3-2 -> 1:5.9.4-1
$ sudo pacman -Syu
:: Synchronizing package databases...
core 134.5 KiB 193 KiB/s 00:01 [#################################################] 100%
extra 1698.5 KiB 765 KiB/s 00:02 [#################################################] 100%
community 5.0 MiB 1190 KiB/s 00:04 [#################################################] 100%
:: Starting full system upgrade...