lspci for linux as a shell script

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.

Add new comment

Default

  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You may link to images on this site using a special syntax
  • Web page addresses and e-mail addresses turn into links automatically.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Filtered words will be replaced with the filtered version of the word.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <q>

Issue

  • Lines and paragraphs break automatically.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>

Drinking Game

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <p> <br> <pre> <h2> <h3> <h4>
  • Images may be embedded like: [image:node_id align=alignment hspace=n vspace=n border=n size=label width=n height=n nolink=(0|1) class=name style=style-data node=id] Leave off any attributes you don't want.
  • [img_assist|...] tags will be displayed, maybe. Please don't make more of them.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.