Saturday, September 23, 2006

 

linux ifconfig compact output

Read somewhere that writing a blog is a good way to make myself
more visible on the net. Good for job search, etc.
Also thought it might be useful to others to record
my occasional findings.

ifconfig prints something like the the following by default:

ifconfig
eth0 Link encap:Ethernet HWaddr 00:0B:DB:2E:3C:05
inet addr:10.27.11.233 Bcast:255.255.255.0 Mask:255.255.252.0
inet6 addr: fe80::20b:dbff:fe2e:3c05/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7440425 errors:0 dropped:0 overruns:0 frame:0
TX packets:174599 errors:0 dropped:0 overruns:0 carrier:0
collisions:30134 txqueuelen:1000
RX bytes:1530104868 (1.4 GiB) TX bytes:121416585 (115.7 MiB)
Interrupt:11

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:505339 errors:0 dropped:0 overruns:0 frame:0
TX packets:505339 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:158945307 (151.5 MiB) TX bytes:158945307 (151.5 MiB)


I am running this on Fedora 5.
There is also a "short" version:

ifconfig -s

Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 7440754 0 0 0 174615 0 0 0 BMRU
lo 16436 0 505367 0 0 0 505367 0 0 0 LRU


Sometimes I want a different output, lets say a "compact" output.
Turns out this is easy to do.
I modified the existing ifconfig source code and the result is:

ifconfig -c
eth0 encap:Ethernet HWaddr:00:0C:29:3B:F3:69 inet:10.27.11.106 Mask:255.255.252.0 UP RUNNING MTU:1500
lo encap:Local Loopback HWaddr:null inet:127.0.0.1 Mask:255.0.0.0 UP RUNNING MTU:16436


Each line is one interface, and each field is separated by
a SPC (space) char, and some fields are key:value.
This output is more suitable for scripting.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?