Watch USB Connections – Vendor ID, Product ID, and Revision

linuxudevusb

I'd like to simply watch all devices added and removed from my system and view their USB vendor ID, product ID and revision and other relevant information. How can I do this in Linux? Is there a logfile that I can tail -f or does this require something else?

Best Answer

This information appears in the kernel logs — typically in /var/log/kern.log, or /var/log/syslog, or some other file (it depends on your syslog configuration, different distributions have different defaults).

If you'd like something pre-filtered, you can add an udev rule. Create a file /etc/udev/rules.d/tkk-log-usb.rules containing something like:

SUBSYSTEM=="usb", RUN+="/usr/local/sbin/tkk-usb-event"

The environment of the program is populated with a lot of variables describing the device, including:

  • ACTION (add or remove)
  • DEVICE is a path to the device if you want to access it
  • ID_MODEL_ID and ID_VENDOR_ID contain the model and vendor ID, and ID_MODEL and ID_VENDOR contain the corresponding text
  • ID_SERIAL contains the serial number of the device (if available)
Related Question