Linux-like top/netstat/etc. on Mac OS X?

Unix utilities on Mac OS X are quite painful to use. port install coreutils +with_default_names and a few other such replacements fix most of them, but it leaves some in broken Mac OS X defaults - most annoyingly top and netstat, but I'm sure I could think of a few more.

I'm guessing that commands like top and netstat are quite OS specific, so just grabbing sources of their Linux equivalents and recompiling won't work.

What's the best equivalent of these and other such commands that works on Mac OS X?


Solution 1:

Many netstat features can be replaced with a lsof command. I was often using

netstat -lnp | grep 1234

to find out who was listening on port 1234. With lsof (that is available on both systems), I can do:

lsof -i :1234

The top command on OSX is not bad either, it's just different. And I'm quite sure some of the metrics only make sense on Mac.

Note that lsof -Pi :1234 should make it a bit faster by not trying to resolve the service names (of the ports).

Solution 2:

Oh cool, htop is in Homebrew! I guess it isn't a clone of Linux top but if you decide to use htop on Linux then I guess htop on OS X won't be too far off.