28

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?

4
  • 3
    Calling them "replacements" may not be historically accurate. They are derived from the BSD variants, and historically many of those predate the linux tools that you are used to. Good questions though, and similar issues exist for those of us who use fink instead of ports. Aug 1, 2010 at 21:37
  • 5
    Your question would be better if it contained less editorializing. Crossing over from one Unix-like OS to another always brings surprises in the way different common Unix commands have followed different evolutionary paths on different platforms. I've used Solaris, DEC Ultrix, AT&T SysV, HP-UX, GNU/Linux (many distros), NEXTSTEP, OpenStep, BSDI, Xenix/SCO, FreeBSD, NetBSD, Mac OS X, and CygWin. If you let yourself get too accustomed to unique features of one flavor's tools, it's painful when you go to another favor. That doesn't make them "broken".
    – Spiff
    Aug 2, 2010 at 7:24
  • 2
    Right, and don't forget Hurd. Other than Linux and OSX, the rest of your list is of historical interest only.
    – taw
    Aug 2, 2010 at 16:05
  • @taw: Solaris is still in use in a lot of places, particularly for zfs.
    – Dan
    Dec 29, 2015 at 23:32

2 Answers 2

29

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).

3
  • 7
    OSX lsof is better better netstat than OSX netstat, thanks.
    – taw
    Aug 2, 2010 at 15:56
  • add -P to prevent name resolution and make it way faster. So linux netstat -ntlp kinda like lsof -Pi | grep -i listen. Still don't know how multiple PID's could listen on the same port, not something I see in linux :/
    – Ray Foss
    Jul 12, 2017 at 18:56
  • @RayFoss On Mac and some other OS, a process can listen on .:1234 and another one on 127.0.0.1:1234. The latter having the precedence. That's forbidden on Linux. Jul 13, 2017 at 10:10
5

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.

1
  • 1
    its not a direct replacement as you cant get a quick list of listening servers
    – Ray Foss
    Jul 12, 2017 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.