for depfiles in `pkg info -d packagename`; do if [ `pkg info -r $depfiles |wc -l` == 2 ]; then echo $depfiles;fi;done |tee -a dellist pkg delete `cat dellist` pkg set to prevent packages removed by pkg autoremove. pkg autoremove normally does not remove packages that still needed. It only removes packages pkg set -A0 you can set every package to register as non-automatic. So pkg autoremove does not touch it. pkg autoremove does something different on your system, there is something wrong with your installed ports or packages. pkg set -A0 is a good alternative if one knows all automatic packages that one still needs. But if one only knows that one does not need some packages, for example the ones installed as dependence of a specific package, then it is danger to delete any non-automatic. This is for example the case if you compiled some programs in /usr/opt and the configuration scripts decided about the dependencies.