Skip to content

Instantly share code, notes, and snippets.

@Higgs1
Created February 26, 2021 23: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 Higgs1/fa483adfa58f4b2955f13e57efec4087 to your computer and use it in GitHub Desktop.
Save Higgs1/fa483adfa58f4b2955f13e57efec4087 to your computer and use it in GitHub Desktop.
get_dev_by_usb_id() {
idV=${1%:*}
idP=${1#*:}
for path in $(find /sys/ -name idVendor 2> /dev/null | rev | cut -d/ -f 2- | rev); do
if grep -q $idV $path/idVendor; then
if grep -q $idP $path/idProduct; then
for bd in $(find $path -name 'device' | grep 'block' | rev | cut -d / -f 2 | rev); do
echo "/dev/$bd"
done
fi
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment