How to shorten ifconfig to get eth * details alone?

I am writing a script to print the details of the ethtool ifconfig.

The output sample should be from ifconfig, like,

eth0 eth1 eth2 

I tried using the command below,

 root@bt # ifconfig | cut -d ":" -f 1 

But could not achieve the same.

Actually, I need to get these eth* and pass

 root@bt # ethtool <arg1> where arg1=eth* 

to get the results :-) Could you help me get the crop with ifconfig.

0
source share
2 answers

With grep and ifconfig :

 ifconfig | grep -o '^eth[0-9]\+' 

Or just with grep :

 grep -oP '^ *\Keth[0-9]+' /proc/net/dev 
0
source

No.

 $ awk -F: '$1 ~ "eth" { print $1 }' /proc/net/dev eth0 
+1
source

Source: https://habr.com/ru/post/1437876/


All Articles