Homebrew, list all packages which are no dependency of other installed packages

homebrew

There is the awesome vanilla list:

$ brew list | cat
[...]
libevent
[...]
net-snmp
[...]
openssl
openssl@1.1
[...]

Let's say I want to check which packages can I remove because I no longer need. I would need a way to forge such list, because if I try to randomly remove a package, e.g. openssl@1.1:

$ brew remove openssl@1.1
Error: Refusing to uninstall /usr/local/Cellar/openssl@1.1/1.1.0f
because it is required by net-snmp, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies openssl@1.1
$ _

So my desired output would be:

$ /PATH/TO/brew_dependency_tree_leaves_list.sh
[...]
libevent
[...]
net-snmp
[...]
$ _

I don't know if net-snmp can be depended by any. It is not in my scenario. libevent is also depended upon by something else, but please abstract that.

How to?

Best Answer

$ brew leaves

Docs:

List installed formulae that are not dependencies of another installed formula.