Daerandin
Well-Known Member
I was just tinkering around with the idea of how to easily check if there could be issues with installed packages on my system. One simple way would be to check if any installed packages are missing files. Files missing on your system could of course come from a number of reasons, but knowing if it happens early can help prevent further loss of data.
This should work on any distribution that use the pacman package manager, but a similar check should be easy to implement on other distros provided the package manager have an easy way to check if installed packages are missing files.
pacman -Qk lists all installed packages, how many files are associated and if any are missing. Now browsing through the entire output might tiresome so you could use grep to just find lines with missing packages. A sample output from the command is:
I actually have localized output, but I simple ran the command with LC_ALL=C to make it readable for others.
The interesting part here is after the comma, that's where it states if files are missing or not. So you can use awk to filter the output. I use this as part of a script that only check the exit status after the finished line, but if you run the following command and get no output, then your installed packages are not missing any files, which is good.
The command must be run as root, as a regular user do not have access to certain directories which will prevent the command from successfully checking for all files.
So if you run this command and get no output at all, you are good. However, actual output from this command is not going to be very useful since it will not display what packages are missing files, so another approach would be to simply run
This will display any packages that are missing files. I used LC_ALL=C in case you have a different locale than english, or you could simply replace the string in grep to match what it says on your language.
I don't know if this is useful to anyone else, but it's just something I found to be useful and wanted to share. I actually incorporated this little check as part of my backup script so it does not start the backup if such breakage is detected, and instead warns me.
This should work on any distribution that use the pacman package manager, but a similar check should be easy to implement on other distros provided the package manager have an easy way to check if installed packages are missing files.
pacman -Qk lists all installed packages, how many files are associated and if any are missing. Now browsing through the entire output might tiresome so you could use grep to just find lines with missing packages. A sample output from the command is:
Code:
xsane-gimp: 8 total files, 0 missing files
xscreensaver-arch-logo: 747 total files, 0 missing files
xterm: 36 total files, 0 missing files
I actually have localized output, but I simple ran the command with LC_ALL=C to make it readable for others.
The interesting part here is after the comma, that's where it states if files are missing or not. So you can use awk to filter the output. I use this as part of a script that only check the exit status after the finished line, but if you run the following command and get no output, then your installed packages are not missing any files, which is good.
The command must be run as root, as a regular user do not have access to certain directories which will prevent the command from successfully checking for all files.
Code:
sudo pacman -Qk | awk -F , '{ print $2 }' | grep -v '^ 0'
So if you run this command and get no output at all, you are good. However, actual output from this command is not going to be very useful since it will not display what packages are missing files, so another approach would be to simply run
Code:
LC_ALL=C sudo pacman -Qk | grep -v '0 missing files'
This will display any packages that are missing files. I used LC_ALL=C in case you have a different locale than english, or you could simply replace the string in grep to match what it says on your language.
I don't know if this is useful to anyone else, but it's just something I found to be useful and wanted to share. I actually incorporated this little check as part of my backup script so it does not start the backup if such breakage is detected, and instead warns me.