List only the device names of all available network interfaces

Give this a try:

ifconfig -a | sed 's/[ \t].*//;/^$/d'

This will omit lo:

ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d'

Another alternative would be:

ip -o link show | awk -F': ' '{print $2}'

Or maybe:

ls /sys/class/net

Just use /sys/class/net and strip out the path:

$ basename -a /sys/class/net/*
eth0
eth1
lo
ppp0
tun0

A more modern way would be to use the iproute json output and a parser, like:

$ ip -j link |jq -r '.[].ifname'
lo
wlp0s20f3
enp0s31f6
virbr0
virbr0-nic

Which allows you to filter out the loopback interface:

$ ip -j link |jq -r '.[].ifname | select(. != "lo")'
wlp0s20f3
enp0s31f6
virbr0
virbr0-nic

Try this:

ifconfig | cut -c 1-8 | sort | uniq -u
  • cut -c 1-8 extracts the first 8 characters of each line
  • sort sorts the lines
  • uniq -u prints only unique lines which will remove the blank lines for the description lines which have only spaces in their first eight characters

This works on two linux machines I tried, but on my MacBookPro (OS X 10.6.4), ifconfig uses tabs instead of spaces, so it's a bit more complicated:

ifconfig | expand | cut -c1-8 | sort | uniq -u | awk -F: '{print $1;}'
  • expand converts tabs to spaces
  • awk -F: '{print $1;}' prints the first field before a colon.