Skip to content

Instantly share code, notes, and snippets.

@stevenvo
Created March 19, 2016 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenvo/315ea3a9934636aecb4d to your computer and use it in GitHub Desktop.
Save stevenvo/315ea3a9934636aecb4d to your computer and use it in GitHub Desktop.
A script that walks through devices in /sys looking for USB devices with a ID_SERIAL attribute. Typically only real USB devices will have this attribute, and so we can filter with it. If we don't, you'll see a lot of things in the list that aren't physical devices.
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment