The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
FreeBSD Support
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Cleaning junk out of /usr/local
Author: Justin Hawkins 
Date:   08-09-00 15:18

It had always concerned me a little about the way stuff accumulates in /usr/local, if you're anything like me you like to experiment, installing bits and pieces here and there, and over time you forget what exactly /usr/local/bin/dowhatsit belongs to.

I thought about it for a while and wondered if there was a way I could find out which files belong to properly installed ports, and what is just stray rubbish. It didn't take me long to hack this together:

[Following should be all on one line]

pkg_info -a -L > /tmp/pkg_info.txt ; for FILE in `find /usr/local -type f` ; do echo -n
$FILE : ; if grep $FILE /tmp/pkg_info.txt > /dev/null ; then echo OK ; else
echo Not in package database ; fi ;done > /tmp/whatswhat.txt

When it's finished you can take a look in /tmp/whatswhat.txt and quickly find those orphaned files.

This is way from perfect (for instance a 'cat' file is created every time you run 'man' and they will show up. This shouldn't be used to blindly delete stuff, more as a guide. If anyone has any suggestions for improving this let me know!

- Justin

Reply To This Message
 RE: Cleaning junk out of /usr/local
Author: Don Brearley 
Date:   10-09-00 09:08

donny likey.


Reply To This Message
 RE: Cleaning junk out of /usr/local
Author: Philip 
Date:   13-09-00 18:09

That's pretty cool...

You might want to add "-o -type l" to your find command too so that you catch things like /usr/local/bin/ssh which is a symlink...

I don't know if this if more efficient or not, but it avoids the loop... but then you're sorting a potentially humongous file... anyone know which is better?

( pkg_info -aL | grep "^/usr/local/" ; find /usr/local/ -type f -o -type l ) | sort | uniq -u

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum