# autoremove unneeded ports



## demo (Sep 14, 2010)

Hi, have tried searching google/forum posts for a command to "auto remove" any un-needed ports that i have installed. In a similar fashion to _`apt-get autoremove`_ on debian systems (remove installed packages/libs left behind, after something has been removed).

Either i'm looking at the wrong man pages, or can't seem to find anything.

I have so far looked into _`pkg_delete`_, _`pkg_deinstall`_ and _`portsclean`_
But i am not too sure how to autodetect packages that don't need to be on my system.

What are my options?


----------



## wblock@ (Sep 14, 2010)

It's tricky for the system to tell if a port that nothing depends on is one you might want to keep installed.  Like, say, Firefox.


----------



## Beastie (Sep 14, 2010)

There is sysutils/pkg_cutleaves. But be careful with it since it may also remove all the "top-level" ports, i.e. your applications, since no other port depends on them. If I am not mistaken, you may pass it an exception list file where you can include all your applications.


----------



## mix_room (Sep 15, 2010)

Beastie said:
			
		

> If I am not mistaken, you may pass it an exception list file where you can include all your applications.



`# pkg_cutleaves -x`

/usr/local/etc/pkg_leaves.exclude

```
apache
vi
```

Will exclude all ports starting with apache or vi, apache22 apache13 vi and vim for example.


----------

