[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr da:de:be:41:89:18 inet addr:192.168.150.53 bcast:192.168.150.255 mask:255.255.255.0 Inet6 addr:fe80::d 8de:beff:fe41:8918/64 Scope:link Up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:184255445 errors:0 dropped:0 overruns:0 frame:0 TX packets:51947 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12701252470 (11.8 GiB) TX bytes:4422271 (4.2 MiB) Interrupt:17 |
Method 1: Match inet addr This line, the 2nd paragraph is displayed with a colon delimiter, the 1th paragraph is displayed again as a space separator
[Email protected] ~]# ifconfig eth0 |grep ' inet addr ' |cut-d:-f2 |cut-d ""-f1
Method 2: Match inet addr This line; Replaces the string from the beginning to the addr: with NULL, replacing the string from bcast to end again with empty
[Email protected] ~]# ifconfig eth0 |grep ' inet addr ' |sed ' s/^.*addr://g ' |sed ' s/bcast.*$//g '
Method 3: Match inet addr this line; or a space as a delimiter, and then print the 4th column
[[email protected] ~]# ifconfig eth0 |grep ' inet addr ' |awk-f[: ""]+ ' {print $4} '
Method 4: Match inet addr this line; To: As a delimiter, print the 2nd column, and then print the first column
[[email protected] ~]# ifconfig eth0 |grep ' inet addr ' |awk-f: ' {print $} ' |awk ' {print $} '
Method 5:
[[email protected] ~]# ifconfig eth0|sed-nr ' 2s#^.*addr: (. *) Bcast.*$#\1#g ' P
Method 6:
[email protected] ~]# ifconfig eth0 |awk '/inet addr:/ {print $} ' |awk-f: ' {print $} '
Method 7:
[Email protected] ~]# ifconfig eth0 |awk '/inet addr:/ {print $} ' |awk-f: ' {print $} '
Method 8:
[[email protected] ~]# ifconfig eth0 |awk ' nr==2 {print $} ' |awk-f: ' {print $} '
Method 9:
[email protected] ~]# IP Add |awk-f ' [/]+ ' nr==8 {print $} '
This article is from the "M April Days" blog, please be sure to keep this source http://msiyuetian.blog.51cto.com/8637744/1733259
9 ways to view IP addresses in Linux