Reputation: 156
When I use ifconfig
command, it will show the details of all active devices.
I want the interface name only, and want to check whether the interface is running or not.
ifconfig | grep interface-name
This will give all detail about the interface but I want to print only interface name.
Upvotes: -1
Views: 1484
Reputation: 1774
To see (only) Interface Name, IF Name, you could try these commands in the Terminal (from name of my Network Interface?):
ip route list | grep default | awk '{print $5} '
This is for the default route.
or
ls /sys/class/net
This is for all names.
Upvotes: 0
Reputation: 95998
Since you have the interface name, you can do the following:
$ ifconfig interface-name &> /dev/null
$ echo $?
If the output is 0, the interface exists, otherwise, it doesn't.
Upvotes: 2