Displaying received data on an interface

In this example, we will print just the received data from the eth0 interface.

This is the interface that is my primary network connection. If you are uncertain of your interface name, you can use the ifconfig -a command to display all the interfaces and choose the correct interface name on your system. If ifconfig is not found, try typing the full path, /sbin/ifconfig.

Using just the ifconfig eth0 command, a heap of data can be printed to the screen. To show just the packets received, we can isolate the lines that contain RX packets (RX for received). This is where grep comes in:

$ ifconfig eth0 | grep "RX packets"  

Using the pipe or vertical bars, we can take the output of the ifconfig command and send it to the input of the grep command. In this case, grep is searching for a very simple string, RX packets. The search string is case sensitive, so we need to get this right or use the -i option with grep to run the search as case insensitive, as shown in the following example:

$ ifconfig eth0 | grep -i "rx packets"  
A case-insensitive search is especially useful when searching for options in a configuration file, which often have mixed cases.

We can see the result of the initial command in the following screenshot, confirming that we have been able to isolate just the single line of output, as shown: