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

16,942

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.

Share:
16,942

Related videos on Youtube

taw
Author by

taw

Ruby/Perl/Python/* freelancer from London. Writes a blog and codes some Open Source stuff in free time.

Updated on September 17, 2022

Comments

  • taw
    taw over 1 year

    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?

  • taw
    taw almost 14 years
    OSX lsof is better better netstat than OSX netstat, thanks.
  • Ray Foss
    Ray Foss almost 7 years
    its not a direct replacement as you cant get a quick list of listening servers
  • Ray Foss
    Ray Foss almost 7 years
    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 :/
  • Eric Darchis
    Eric Darchis almost 7 years
    @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.