Posted: . At: 11:00 AM. This was 6 years ago. Post ID: 12104
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



Another way to get only interface names from a Linux machine.


How to return only interface names when listing all installed network interfaces in a Linux box.

jason@jason-Lenovo-H50-55:~/Documents$ ip link | grep -Po "(?<=^\d: |^\d\d:)[^:]+(?=:)"
lo
eth0
wlan0

This is very useful to get a listing of all networking interfaces for use in a script.

Do it this way using ifconfig.

jason@jason-Lenovo-H50-55:~/Documents$ ifconfig | grep -oP '^[^ ]*'
eth0
lo
wlan0

This is great if the user is writing a script and wishes to get a listing of all network interfaces.

This is a final way of listing all interface names. This could be used in a C program with execve().

jason@jason-Lenovo-H50-55:~/Documents$ ls -1 /sys/class/net
eth0
lo
wlan0

This is very useful information to any Linux user. I hope someone like this info. I was looking for a long while on how to do this.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.