是否可以在不使用egrep的情况下打印DEVICE enp0s9的状态?
$ nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected Wired connection 1
enp0s9 ethernet connected Wired connection 2
lo loopback unmanaged --
$
我希望仅使用nmcli
命令而不是使用外部命令(例如egrep
$ nmcli device status | egrep 'D|9'
DEVICE TYPE STATE CONNECTION
enp0s9 ethernet connected Wired connection 2
$
答案1
只是为了在问题一年后出现的时候帮助其他人......
[user@host]# nmcli -g general.state device show enp0s9
100 (connected)
nmcli 每行显示一个数据。要获取您提供的相同数据,请这样做:
[user@host]# nmcli -m multiline -g general.device,general.type,general.state,general.connection device show eth0
GENERAL.DEVICE:enp0s9
GENERAL.TYPE:ethernet
GENERAL.STATE:100 (connected)
GENERAL.CONNECTION:Wired connection 2
删除-m multiline
您将收到不带关键字前缀的默认格式:
[user@host]# nmcli -g general.device,general.type,general.state,general.connection device show eth0
enp0s9
ethernet
100 (connected)
Wired connection 2
省略选项-g 一般状态将为您提供所有可用数据,如下所示:
[user@host]# nmcli device show eth0
GENERAL.DEVICE: enp0s9
GENERAL.TYPE: ethernet
GENERAL.HWADDR: B6:20:89:30:E8:03
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: Wired connection 2
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 10.10.0.100/16
IP4.GATEWAY: 10.10.0.1
IP4.ROUTE[1]: dst = 10.10.0.0/16, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 10.10.0.1, mt = 100
IP4.DNS[1]: 1.1.1.1
IP4.DNS[2]: 1.1.1.2
IP6.ADDRESS[1]: fe80::652c:ff98:a178:aa73/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255