Skip to content

Instantly share code, notes, and snippets.

@woernsn
Created July 11, 2025 08:04
Show Gist options
  • Select an option

  • Save woernsn/4c66be295c28ee94aa79c50e59eb0302 to your computer and use it in GitHub Desktop.

Select an option

Save woernsn/4c66be295c28ee94aa79c50e59eb0302 to your computer and use it in GitHub Desktop.
get /sys path from lsusb
#!/bin/bash
#
# usb2sys - find lsusb device in /sys file system
#
# Modified script from https://serverfault.com/a/984649
usb_devices=($(lsusb | cut -d ' ' -f 6))
for usb_device in "${usb_devices[@]}"
do
vendor=${usb_device%:*}
product=${usb_device##*:}
sys=/sys/bus/usb/devices/
cd $sys
for d in *; do
path=$sys$d
if [ -f $path/idProduct ]; then
prod=$( cat $path/idProduct )
vend=$( cat $path/idVendor )
if [ $prod = $product -a $vend = $vendor ]; then
echo vend = $vend
echo prod = $prod
echo /sys device is $path
echo
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment