Find and remove residual config files

Is there any way to find and remove leftover config files automatically.

Say if I remove the nginx package the nginx.conf will still be hang in there until I manually remove it.

Over time I have installed and removed several packages and it is time to do a spring clean of my server.
 
pkg-which(8) might be useful.

Code:
root@maelcum:~ # pkg which /usr/local/etc/nginx/nginx.conf-dist
/usr/local/etc/nginx/nginx.conf-dist was installed by package nginx-1.22.1_5,3
Note that the config file itself isn't installed by a package. But there's usually a *.sample or some other copy of the config that is installed with the package.
 
pkg-which(8) might be useful.

Code:
root@maelcum:~ # pkg which /usr/local/etc/nginx/nginx.conf-dist
/usr/local/etc/nginx/nginx.conf-dist was installed by package nginx-1.22.1_5,3
Note that the config file itself isn't installed by a package. But there's usually a *.sample or some other copy of the config that is installed with the package.

From my quick test, it looks like this will only work either if the package database is still in /var or the package is still installed.

Maybe I can write a shell script to identify all the files which returns an error and go from there..
 
But don't automate that. Things like /etc/rc.conf are not from a package but will be surely missed when gone.
 
Yeah, you can automate the scanning itself, but I wouldn't automate the removal.
 
But don't automate that. Things like /etc/rc.conf are not from a package but will be surely missed when gone.

Yeah, you can automate the scanning itself, but I wouldn't automate the removal.


Of course I was talking about the scanning part and also in /usr/local.

Code:
#!/bin/sh
# Define the directory to search
dir_to_search="/usr/local"
# Define the output file
output_file="config_files.txt"
# Loop through all files under the directory recursively
find "$dir_to_search" -type f | while read file_path; do
# Run the "pkg which" command on each file and write the output to the file
pkg which "$file_path" >> "$output_file"
done
 
Back
Top