Assuming your broken packages are reported as missing files, you can use Qk
to check packages (from man pacman
):
-k, --check
Check that all files owned by the given package(s) are present on the system. If packages are not specified or filter flags are not provided, check all installed packages.
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.
So this command should give you the full list of broken packages on your system (the example below is the result on my Arch):
$ pacman -Qk 2>/dev/null | grep -v ' 0 missing files'
at: 45 total files, 1 missing file
audit: 196 total files, 4 missing files
bind: 413 total files, 3 missing files
blueman: 791 total files, 1 missing file
gdm: 501 total files, 6 missing files
gnome-perl: 71 total files, 18 missing files
gnome-vfs-perl: 61 total files, 27 missing files
gnomecanvas-perl: 39 total files, 17 missing files
gvfs: 324 total files, 1 missing file
hplip: 2294 total files, 72 missing files
mariadb: 354 total files, 1 missing file
nfs-utils: 111 total files, 3 missing files
perl-goo-canvas: 59 total files, 18 missing files
perl-gtk2-imageview: 36 total files, 19 missing files
perl-term-shellui: 21 total files, 6 missing files
polkit: 201 total files, 1 missing file
samba: 976 total files, 1 missing file
syslinux: 237 total files, 2 missing files
systemd: 1891 total files, 1 missing file
Then, this command will print just the package name:
$ pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1
at
audit
bind
blueman
gdm
gnome-perl
gnome-vfs-perl
gnomecanvas-perl
gvfs
hplip
mariadb
nfs-utils
perl-goo-canvas
perl-gtk2-imageview
perl-term-shellui
polkit
samba
syslinux
systemd
You can just iterate over that list and reinstall each of them:
pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1 |
while read -r package; do
pacman -S "$package" --overwrite "*" --noconfirm
done
Or, if the list isn't too long, you could even do:
pacman -S "$(pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1)" \
--overwrite "*" --noconfirm
Note that I have not tested this and I am taking your word for it that the command will fix your packages. You might also want to run sudo pacman -Qkk 1>/dev/null 2>&1 | grep checksum
to check for files that have been modified unexpectedly, as suggested by Tom Yan in the comments.
Finally, also be aware that the Arch documentation warns against using the --overwrite
option (thanks to Ben Mordecai for pointing that out in a comment):
Generally avoid using the --overwrite option with pacman. The --overwrite option takes an argument containing a glob. When used, pacman will bypass file conflict checks for files that match the glob. In a properly maintained system, it should only be used when explicitly recommended by the Arch developers. See the #Read before upgrading the system section.
Of course, in your case you do not have a properly maintained system because of the power failure during upgrade, so this is might be a good use case for it.