How to clean up /usr/local

I want to find all files in /usr/local which do not belong to an installed package as given by "pkg info" and have them automaticly removed. Offcourse no removal in /usr/local/etc.
[ I have had several core dumps off pkg when installing (bad/wrong) .txz manually so there might be stuff lying around ]
Maybe if I list all the files and then lookup for "the package providing file" and in absence "rm -f" ?
I come up with
Code:
find /usr/home 2> /dev/null | xargs -I {} pkg which {} | grep "not found" | grep -v etc | awk '{print $1}' | xargs -I {} rm -f {}
 
This remembers me of my Windows time. Let's evaluate if bsd has better tooling for free.
There are 500.000 files in /usr/local, no kidding.
Decideded to taken the primelist and remove all packages, clean manually /usr/local. Seemed to be not much lying around. Reinstallation of the primelist is a bit slow. Looks like PC is slower in single user mode. I don't know why.
You must do installation in multi-user mode it is 10x faster
In comparison to Windows this is a much cleaner solution.
 
Better idea,
Code:
pkg query -e "%a = 0" "%o" > primelist.txt
Remove all packages &
rm -fR /usr/local except etc
Compare to cleanup a Windows registry.
 
/usr/local/share is where all the fluxbox styles are located, Gimp tools, licenses and just about everything you do not want to delete with /usr/local.
 
I'd pkg list | grep ^/usr/local/ | sort > list1 and find /usr/local/ | sort > list2 and then take a look at diff list1 list2.
 
Better idea,
Code:
pkg query -e "%a = 0" "%o" > primelist.txt
Remove all packages &
rm -fR /usr/local except etc
Compare to cleanup a Windows registry.
For anyone reading this thread who might think this is a good idea, this will remove all configuration files for any services you have installed through ports or packages.
 
True, some configuration is sometimes written sometimes outside /usr/local/etc.
Eg. sometimes in /usr/local/www
Which is a reminder that /var/www is a more logical place for it and /usr/local/www should be used for static pages.
 
If you want to try and find your stale files in /usr/local , the following is doing that more or less,
Code:
find /usr/local 2> /dev/null | egrep -v -e "etc|ruby|perl|python|lib|www|share|include|man|GNUstep|drm-fbsd13-kmod|bootstrap-openjdk11" | xargs -I {} pkg which {} | grep "not found" |  awk '{print $1}'
 
This remembers me of my Windows time. Let's evaluate if bsd has better tooling for free.
There are 500.000 files in /usr/local, no kidding.
Decideded to taken the primelist and remove all packages, clean manually /usr/local. Seemed to be not much lying around. Reinstallation of the primelist is a bit slow. Looks like PC is slower in single user mode. I don't know why.
You must do installation in multi-user mode it is 10x faster
In comparison to Windows this is a much cleaner solution.
How in the world did you get 500k files in there?
 
I want to find all files in /usr/local which do not belong to an installed package as given by "pkg info" and have them automaticly removed. Offcourse no removal in /usr/local/etc.
[ I have had several core dumps off pkg when installing (bad/wrong) .txz manually so there might be stuff lying around ]
Maybe if I list all the files and then lookup for "the package providing file" and in absence "rm -f" ?
I come up with
Code:
find /usr/home 2> /dev/null | xargs -I {} pkg which {} | grep "not found" | grep -v etc | awk '{print $1}' | xargs -I {} rm -f {}
The hell are you talking about?
You look for files in /usr/home. Not a single pkg will install anything there...

If you don't save files explicitly in /usr/local, pretty much every file in there is from pkg.

Seriously man. Your posts on this forum are something else...
 
When you remove packages, it takes care of most files in /usr/local/. It would be better to list what's left behind, but there's so little left behind, that you wouldn't need a special tool for that. Most of what's left behind would be custom configuration files. After careful inspection, you can go into /usr/local/etc/ and delete what you see as necessary to.
 
mv /usr/local to /usr/local.old; mv /var/db/pkg to /var/db/pkg.old; install all the packages you want; cp config files from /usr/local.old/etc to /usr/local/etc. Delete /usr/local.old and /var/db/pkg.old dirs after a while.
 
Back
Top