5

Trying to see if it's possible to limit the output of the lspci command to show only Ethernet devices. The -d switch seems like it should work, but nothing I've tried gets the job done. For example:

lspci -d '*:*:02'

still shows all pci device classes. I'm using 02 as the class per the values found here: http://pci-ids.ucw.cz/read/PD/02

For reference here is the "man lspci" info for the -d switch:

-d [<vendor>]:[<device>][:<class>] Show only devices with specified vendor, device and class ID. The ID's are given in hexadecimal and may be omitted or given as "*", both meaning "any value".

I'm currently using grep to filter output, and that gets the job done:

lspci -vv | grep -A20 Ethernet

3 Answers 3

8

If you'll remove the * and extend the class value to 4 digits the required result will be achived

$ lspci -d ::0200
81:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
81:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)

Update: Class based filter works only with pciutils v3.3.0 or later (see changelog). For RHEL/CentOS this means 7.3 or newer.

2
  • Confirmed this works. In my case, it gives the same output as the answer from LogicalMethods using lspci -d :07b0. Thanks for the answer! May 12, 2018 at 17:58
  • Excellent, thank you. Worked great for me on Ubuntu 16.04. Wish the docs said this! Jun 22, 2020 at 10:32
3

man lspci in my system doesn't show that -d option can be used to show classes, but you can get their names in machine-readable mode, thus grepping it. I.e.:

$ lspci -vmm | grep -B1 -A2 '^Class.*Ethernet'
Slot:   08:00.0
Class:  Ethernet controller
Vendor: Intel Corporation
Device: 82574L Gigabit Network Connection

Another option would be to use sysfs directly. I.e. you can find all ethernet devices by 'c02' string in modalias:

$ find /sys/devices/ -name modalias | xargs grep -l c02
/sys/devices/pci0000:00/0000:00:1c.2/0000:03:00.0/modalias
                                          ^^^ PCI port

or by using systool:

$ systool -b pci -A modalias | awk '
     /modalias.*c02/ { 
          system("/sbin/lspci -s " dev); } 
     { dev = $1; }'
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 11)
2
  • Thanks for the info but I'm actually looking for the "Physical Slot:" value as provided by lspci -vv to use in the answer I posted to this question: unix.stackexchange.com/a/339280/69122 Jan 22, 2017 at 10:23
  • So the solution using systool to find the dev value for -s will give me the output I want if I also pass -vv to the lspci command. BTW, nice example of leveraging awk on that one! Jan 22, 2017 at 10:35
3

To get the results you want you will need to use the pci IDs that are found here rather than the one you were using:

http://pci-ids.ucw.cz/

for instance for a vmware ethernet controller the command would be:

lspci -d :07b0
1
  • Confirmed that works. Thanks for the alternative. I'll need to alias that command as 07b0 isn't something that going to stick in my mind particularly! Jan 26, 2018 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .