Wednesday, June 4, 2008

Script for removing orphans in Arch Linux

Shell scripting is fun, so I created a small function that removes all orphaned packages as reported by Pacman. It calls itself recursively if removing the current orphans revealed any new ones. Tested with zsh since that is my personal preference the best shell around :) - but it probably runs under bash as well. Here is the code:


remove_orphans() {
for pkg in `pacman -Qdt|awk -F ' ' '{ printf("%s\n", $1) }'`; do
sudo pacman -R $pkg
done
if [ `pacman -Qdt|wc -l` -gt 0 ]; then remove_orphans; fi
}

No comments: