Lately, I have been reinstalling Arch from scratch on several machines. When doing so, it is very handy to replicate your packages and that is actually very easy to do with Arch Linux.

Create a package list

The following command creates a list with your packages, that you can curate and store under private versioning control.

pacman -Qqen > pkglist.txt

And this will create a list with the packages that were installed external to the pacman database, either manually installed or from the AUR.

pacman -Qqem > localpkglist.txt

Also, I store my dot files and some of my etc files in a private git repo.

Install from the package list

In order to install from these lists you can do

sudo pacman -S --needed $(comm -12 <(pacman -Slq|sort) <(sort pkglist.txt) )

and

pacaur -S --noedit --noconfirm --needed localpkglist.txt

Other maintenance tasks

This will remove all packages that are not in list. It can be handy to clean up the list and update your system to it.

sudo pacman -Rsu $(comm -23 <(pacman -Qq|sort) <(sort pkglist))

This will remove packages that were installed as dependencies and are no longer needed.

sudo pacman -Rs $(pacman -Qtdq)

Get a backup of modified configuration files ( taken from ms pacman )

pacman -Qii | awk '/^MODIFIED/ {print $2}' | tar -n -cvzf modified_cfg_files.tz -T -

Well, I know there’s hundreds of ways to do this kind of task but here’s my two cents!