Linux-like top/netstat/etc. 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.
Related videos on Youtube
taw
Ruby/Perl/Python/* freelancer from London. Writes a blog and codes some Open Source stuff in free time.
Updated on September 17, 2022Comments
-
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 annoyinglytop
andnetstat
, but I'm sure I could think of a few more.I'm guessing that commands like
top
andnetstat
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 almost 14 yearsOSX
lsof
is better betternetstat
than OSXnetstat
, thanks. -
Ray Foss almost 7 yearsits not a direct replacement as you cant get a quick list of listening servers
-
Ray Foss almost 7 yearsadd
-P
to prevent name resolution and make it way faster. So linuxnetstat -ntlp
kinda likelsof -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 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.