Occasionally, you may want to see if your network adapter has a cable physically plugged in to it. Using ifconfig, however, will not give you the information you need. Instead, the quickest way to grab this information on a Linux machine is to grab the information out of /sys/class/net/. Here, you will find a folder for each network adapter you have, and within each folder is a list of files representing the properties of its adapter. Specifically, you will need to look at the "carrier" file. If it has a value of 0, the cable will be unplugged. A value of 1 means the cable is plugged in.
Here is a quick example:
Wire Plugged in:
Wire Plugged in Again:
Beware, if you are using cat on an interface that is down, you may get the following error:
cat: /sys/class/net/eth2/carrier: Invalid argument
If so, you will need to ifconfig up your interface before you can use cat.
TIP An easy way to get all the connections in one swoop is to enter the following command:
cd /sys/class/net;grep "" eth*/carrier
And you should get something similar to this:
eth0/carrier:1 eth1/carrier:0 eth2/carrier:1 eth3/carrier:1