我粘贴了ifconfig命令的输出,并希望将mac地址(00:e0:4c:68:00:26)从整个输出重定向到文件。
eth0 Link encap:Ethernet HWaddr 00:e0:4c:68:00:26
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4cff:fe68:26/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:671 errors:0 dropped:0 overruns:0 frame:0
TX packets:4546 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70055 TX bytes:1595889
答案 0 :(得分:0)
尝试一下:
我已将ifconfig的输出存储在变量a
中:
mayankp@mayank:~/$ echo $a
eth0 Link encap:Ethernet HWaddr 00:e0:4c:68:00:26
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4cff:fe68:26/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:671 errors:0 dropped:0 overruns:0 frame:0
TX packets:4546 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70055 TX bytes:1595889
mayankp@mayank:~/$ echo $a| awk -F" " '{print $5}'|head -1 > 'mac_addr.txt'
mayankp@mayank:~/$ cat mac_addr.txt
00:e0:4c:68:00:26
让我知道它是否有效。