CAPTCHA
Image CAPTCHA
Enter the characters shown in the image.
This question is for testing whether or not you are human.
  • Create new account
  • Reset your password

User account menu

Home
The Hyperlogos
Read Everything

Main navigation

  • Home
  • My Resumé
  • blog
  • Howtos
  • Pages
  • Contact
  • Search

lspci for linux as a shell script

Breadcrumb

  • Home
  • User Blogs
  • User Blog
  • lspci for linux as a shell script
By drink | Sat February 14, 2015

I needed a quick version of lspci for looking at some linux systems without pciutils, so I threw this one together in a couple of minutes.

It's very simple, it doesn't tell you what the devices are, but it does tell you what kind of devices they are and what their PCI ID is. Then you can go look that up online to figure out what they are. It wouldn't be a horrible stretch to add support for the pci.ids file, but it wasn't necessary for my purposes.

Anyway, without further ado, here's the script.

#!/bin/sh
IDCLASSES=~/lib/pci.classes

for BUS in /sys/devices/pci????:??
do
  BUSID=`echo ${BUS} | sed 's/pci//'`
  BUSID=`basename ${BUSID}`

  for DEVICE in ${BUS}/${BUSID}:*
  do
    PCIVENDOR=`cat ${DEVICE}/vendor | sed 's/0x//'`
    PCIDEVICE=`cat ${DEVICE}/device | sed 's/0x//'`
    PCICLASS=`cat ${DEVICE}/class | sed 's/0x\(..\).*/\1/'`

    echo -n "`basename ${DEVICE}`: "

    if [ -f ${IDCLASSES} ]
    then
      PCICLASSNAME=`grep \^${PCICLASS} ${IDCLASSES} | cut -f2`
      if [ "x${PCICLASSNAME}x" != "xx" ]
      then
        echo -n "${PCICLASSNAME} "
      else
        echo -n "${PCICLASS} "
      fi
    else
      echo -n "${PCICLASS} "
    fi

    echo "(${PCIVENDOR}:${PCIDEVICE})"
  done
done

And here's the pci.classes file.

00 Unclassified device
01 Mass storage controller
02 Network controller
03 Display controller
04 Multimedia controller
05 Memory controller
06 Bridge
07 Communication controller
08 Generic system peripheral
09 Input device controller
0a Docking station
0b Processor
0c Serial bus controller
0d Wireless controller
0e Intelligent controller
0f Satellite communications controller
10 Encryption controller
11 Signal processing controller
12 Processing accelerators
13 Non-Essential Instrumentation
ff Unassigned class

Note that pci.classes is tab-delimited.

linux
pci
script
  • Log in or register to post comments

Footer menu

  • Contact
Powered by Drupal

Copyright © 2025 Martin Espinoza - All rights reserved