Remove stale & old files not belonging to an installed package in /usr/local

If do by example "touch /usr/local/bin/delethisoldfile".
That file does not belong to an installed package.
How to get a list of all these files ?
 
This should be solveable from the pkg database.
Another way is, as I am doing full reinstalls (upgrade -f)anyway, afterwards something like find /usr/local -type f -ctime +90 should show only some config files under etc (and share/emacs/site-lisp/default.el).
It will find such files only when they get old, but that is good enough for me.

There may, btw, also be stale stuff in the base system - specifically if you do only upgrade-in-place, and happen to have changed src.conf options. So, a similar look into these places may not be wrong.
 
#/usr/local/bin/# pkg which ./* |grep not
# -- some are false positives -- don't delete them -- are symlinks and will ruin parts of
installed ports
# -- some are false postives -- don't delete them -- are directories...
 
There are many files under /usr/local that are not installed. Therefore I would not recommend just deleting everything this produces!

files-not-installed.sh
Code:
#!/bin/sh
# get a list of all files installed by all packages
pkg info --list-files -a | awk -f ./files-not-installed.awk | sort > /tmp/l1
# get a list of all files
find -x /usr/local -type f -or -type l 2>/dev/null | sort > /tmp/l2
# show difference
diff /tmp/l1 /tmp/l2 | less

files-not-installed.awk
Code:
$1 ~ /\/usr\/local\// {c=index($1,":");if(c==0){for(i=1;i<NF;i++){printf "%s ",$i}printf "%s\n",$i}}
 
You shouldn't get any 'left-overs', package build tests are quite strict when it comes to pkg-plist. There may be some configuration files left though, but certainly no binaries or libraries.
 
Back
Top