Created
March 19, 2016 07:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Credit: http://unix.stackexchange.com/questions/144029/command-to-determine-ports-of-a-device-like-dev-ttyusb0