Clean up a dirty FreeBSD ports tree
This is a quick hack for those of you who (as me) usually forget to perform a make clean after make install when installing software using the FreeBSD ports collection.
This is the shell script:
#!/bin/sh # # Search for ports that contain a "work" subdirectory, # then go into that port directory and perform a # make clean for i in `find /usr/ports -name work -type d` do cd `echo "$i" | sed 's/\/[^\/]*$/\//'` make clean done
It simply searchs for directories called work within the ports tree (because this is the name of subdirectories created by the ports tree when building software before installing it), then it removes the last part of the path (the work directory itself) and then it goes into the port directory and performs a make clean to clean up this port (and all the dependencies of the port).
This could be helpful if you only need to clean a given number of ports (10, 20, whatever) and you don't want to perform a full clean:
cd /usr/ports && make clean
This will clean up the whole ports tree, but it will take a loooong time to finish.
Oh!, obviously you need root privileges to execute the script (use sudo to call the script or edit the script and replace make clean with sudo make clean for example).