[Ubuntu] Packages auto-purging script
Here is my script for auto-purging of removed packages (the script deletes remaining configuration files of package) in Ubuntu:
#!/bin/sh for i in `dpkg -l | grep ^rc | cut -f 3 -d ' '` do dpkg -P $i; done
dpkg -l shows list of packages installed in system
grep ^rc print all lines starting with “rc” (in this case print all lines with name of packages which configuration files are still in system)
cut -f 3 -d ‘ ‘ Divides lines into fields using space as delimiter and prints 3rd field (in this case retrieve name of packages to delete)
dpkg -P package purges package
This link explains other things.
Script can also be added to /etc/crontab as:
09 18 * * * root for i in `dpkg -l | grep ^rc | cut -f 3 -d ' '`; do dpkg -P $i; done
Script will be executed with root privileges everyday at 18:09.