$ netstat -nr is great for outputting the Mac OS X IP routing tables.

However its output is long as it contains both IPv4 and IP6 routing tables.

Sometimes I wish to output only the IPv4 routing table. I wish to use short terminal command to only see the IPv4 routing table.

My best result is $ netstat -nr | sed -e '1,3d;/Internet6:/,$d;/^$/d'

Can this command be shortened?

  • 2
    Sorry, but I just can't help myself... One should read the manual page of a given command to see all that it is capable of before trying to figure out how to achieve desired output via piping to other commands. I'm saying this as much for myself as anyone else, because just recently I found myself in a similar situation. I was piping the output of lynx to awk when there was an option in lynx that was doing what awk was. I normally read the man pages however I'll admit I was just being lazy in this case. :) – user3439894 Apr 9 '16 at 13:11
  • @user3439894 I did read the manual pages multiple times. Could not find the option I needed. – Pro Backup Apr 9 '16 at 13:53
  • I skimmed the lynx man page for the option I missed however at 16 pages vs. 4 pages for netstat I didn't feel too bad when it was pointed out to me. :) BTW I was not the down-vote on your question. – user3439894 Apr 9 '16 at 14:41
  • 2
    Even now 1 month after I have asked, I couldn't remember the options, and I couldn't figure out the correct commands from the man pages. Luckily I have asked and that the question is still not deleted, so I can find the answer again. – Pro Backup May 13 '16 at 7:55
$ netstat -nr -f inet
Routing tables

Destination        Gateway            Flags        Refs      Use   Netif Expire
default        UGSc           10        0     en4
default             UGScI           0        0    ppp0
10                 ppp0               USc             0        0    ppp0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .