-1

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.

Maroun
  • 94,125
  • 30
  • 188
  • 241
Yash Shah
  • 158
  • 2
  • 13

2 Answers2

2

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.

Maroun
  • 94,125
  • 30
  • 188
  • 241
0

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.

Cloud Cho
  • 1,594
  • 19
  • 22