I'm studying for the LPIC-1 exam and I'm stuck understanding the following example of the command cut:

ifconfig enp3s0f2 produces the following result:

enp3s0f2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:90:f5:e5:e4:7c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I then run the command ifconfig enp3s0f2 | grep ether | cut -d " " -f 10 which displays this output, as I want to isolate the MAC address: 00:90:f5:e5:e4:7c

However, I only played around with the -f parameter which has 10 as a value. I don't understand why it's 10 and not another number. I've looked at several pages with examples on how to use the cut command and the different arguments, but in this example, it doesn't make sense at all to me.

How to isolate this MAC address it should be the value 10 to be assigned to -f?

  • 1
    On Linux, just use cat /sys/class/net/enp3s0f2/address – Stéphane Chazelas Sep 5 at 10:26
up vote 4 down vote accepted

This is because of the delimiter which we use, we have 8 spaces before ether

We can check by using the below code.

 ifconfig enp3s0f2 | grep ether | sed 's/ether.*//' |grep -o ' ' | wc -l 

 8

So the 9th field is ether and 10th field is 00:90:f5:e5:e4:7c

From man cut:

   -d, --delimiter=DELIM
          use DELIM instead of TAB for field delimiter

   -f, --fields=LIST
          select only these fields;  also print any line that contains no delimiter character, unless the -s option is specified

So you're splitting the output by every delimiting character, in your case a space. This produces an array of fields. The -f option tells cut to only return the 10th field.

  • Hi, Thanks but this doesn't help understand how the MAC address is considered the 10th field based on what was piped, even with the delimiting character being a space. Am I understanding something wrong? Aren't the fields being counted from the word "ether", which would be the first one? If yes, how can the MAC address be the 10th? – Sib Sep 5 at 10:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.