1

I want to find out what is Linux using to control my hardware. I guess modules and drivers and maybe they are the same.

I got this answer : How do I find out which driver a piece of hardware is using?

And there's a way to list the drivers but I also want to add an identifier to each list item.

If I run this command the this is what happens :

sudo lshw | grep -Eo 'driver=[^ ]+' | sort -u | cut -d\= -f2

agpgart-intel

ahci

ath9k

atl1c

ehci-pci

hub

i915

intel

lpc_ich

mei_me

pcieport

snd_hda_intel

tun

usb-storage

uvcvideo
4
  • Do you know what sudo lshw | grep -Eo 'driver=[^ ]+' | sort -u | cut -d\= -f2 does? sudo lshw prints all information about your hardware; the rest of the command filters and sorts the output such that in the end you get a list of drivers in use. If you want all information, just run sudo lshw.
    – danzel
    Mar 2, 2016 at 14:35
  • If you're fine with listing only PCI devices, you could parse lspci -k.
    – kos
    Mar 2, 2016 at 14:39
  • Please edit your question and explain what exactly you want to achieve ("identifier"?).
    – danzel
    Mar 2, 2016 at 15:00
  • Answer posted, please let me know what you think. Also, in the linux world, drivers = modules, they're the same. Mar 2, 2016 at 15:15

1 Answer 1

1

If you are concerned with only filtering output of lshw to show device and its corresponding driver, you can use the lshw and awk combination bellow:

sudo lshw | awk '/product:/{  if(length(PROD) > 0){PROD=""};  for(i=1;i<=NF;i++) PROD=PROD" "$i  } /driver=/{  for(j=1;j<=NF;j++){ if($j~/driver=/) DRIVER=$j   };print "---",PROD,DRIVER; PROD=""}' 

Basic idea here is that we find lines that have "product: . . . " in them and store into PROD. Because some devices don't list drivers, we could have repeatedly appended line after line to PROD variable, so in the beginning we check length of the PROD string. Another matching that is going on, is for the lines containing the driver= part. Once we have that, we print both the product and the driver information.

Bellow is the command put together into a script, and sample output:

$ cat ./dev-drivers.sh                                                                                            
#!/bin/bash

sudo lshw | awk '/product:/{  if(length(PROD) > 0){PROD=""};\
            for(i=1;i<=NF;i++) PROD=PROD" "$i  }\
             /driver=/{  for(j=1;j<=NF;j++){ if($j~/driver=/) DRIVER=$j   };\
             print "---",PROD,DRIVER; PROD=""}' 

$ ./dev-drivers.sh                                                                                                
[sudo] password for xieerqi: 
---  product: ValleyView SSA-CUnit driver=iosf_mbi_pci
---  product: ValleyView Gen7 driver=i915
---  product: ValleyView 6-Port SATA AHCI Controller driver=ahci
---  product: ValleyView USB xHCI Host Controller driver=xhci_hcd
---  product: ValleyView SEC driver=mei_txe
---  product: ValleyView High Definition Audio Controller driver=snd_hda_intel
---  product: ValleyView PCI Express Root Port driver=pcieport
---  product: RTL8101E/RTL8102E PCI Express Fast Ethernet controller driver=r8169
---  product: ValleyView PCI Express Root Port driver=pcieport
---  product: QCA9565 / AR9565 Wireless Network Adapter driver=ath9k
---  product: ValleyView PCI Express Root Port driver=pcieport
---  product: RTS5229 PCI Express Card Reader driver=rtsx_pci
---  product: ValleyView Power Control Unit driver=lpc_ich
2
  • I want to add the description will this work ? sudo lshw | awk '/product:/ {if(length(PROD) > 0){PROD=""}; \for(i=1;i<=NF;i++) PROD=PROD" "$i} \/driver=/ {for(j=1;j<=NF;j++){ if($j~/driver=/) DRIVER=$j}; /description:/ {if(length(DESC) > 0){DESC=""}; \for(i=1;i<=NF;i++) DESC=DESC" "$i} \print "---",PROD, DESC,DRIVER; PROD=""}'
    – userDepth
    Mar 3, 2016 at 13:40
  • Got it working! here a pastebin. pastebin.ubuntu.com/15273502
    – userDepth
    Mar 3, 2016 at 13:59

You must log in to answer this question.

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