Clean FreeBSD Ports Directories

After building and installing software from the ports collection, you should always remember to clean up the temporary work directories. You can sweep the whole ports tree with the following command:

# portsclean -C

The portsclean utility is part of the portupgrade suite.

Alternatively, here’s a shell script:

1
2
3
4
5
6
7
8
9
10
11
12

#!/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