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?
You can do that with
udevadm monitor --subsystem-match=usb --property
udevadm monitor --subsystem-match=usb --property --udev
to filter only
udev events. If you want to
grep for a particular property you will have to un-buffer
udevadm output (with tools like
stdbuf -i 0 -o 0 -e 0 udevadm monitor --subsystem-match=usb --property --udev | grep DEVPATH
script -q /dev/null -c "udevadm monitor --subsystem-match=usb --property --udev" | grep PRODUCT
unbuffer udevadm monitor --subsystem-match=usb --property --udev | grep -E 'ID_VENDOR_ID|ID_MODEL_ID'
This information appears in the kernel logs — typically in
/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:
The environment of the program is populated with a lot of variables describing the device, including:
DEVICEis a path to the device if you want to access it
ID_VENDOR_IDcontain the model and vendor ID, and
ID_VENDORcontain the corresponding text
ID_SERIALcontains the serial number of the device (if available)
If you just want to monitor the current plugged USB devices
watch --no-title lsusb could fit the bill.
dmesgdoes not display all USB events, only ones for which a handler exists and calls