I need to loop over the network interfaces available in Linux. I'm interested in all kinds of interfaces (loopback, ethernet, vlan, bridge) - whatever shows up in ifconfig -a
.
Is there a way to enumerate the interfaces in Linux? By any command or by reading a file?
ifconfig -a | grep 'flags' | wc -l
– orion Jul 02 '15 at 20:18ip
instead as it is a successor ofifconfig
-ip -o link show | wc -l
. See this question – VL-80 Jul 02 '15 at 23:54netdevice(7)
). – o11c Jul 03 '15 at 02:15ls -A1 /sys/class/net eth0 lo usb0 wlan0
In fact, I was surprised to find the count using "wc -l" still works on the single line version of the command (ls -A). But there are likely other situations where the item-per-line output from ls will be preferable, or necessary. – Alex Apr 24 '17 at 01:52