You can use its -d option to query a certain vendor/product (but it seems to work only for currently plugged devices): $ lsusb -d 0e21:0750īus 001 Device 005: ID 0e21:0750 Cowon Systems, Inc. Same with dev_id and INTERFACE= for network interfaces.Lsusb command queries information about currently plugged USB devices. Xargs sed -n -e s,DEVNAME=,/dev/,p -e s,INTERFACE=,pĪ) look through /sys/bus/usb/devices/*:* for a device interface which matches your vendor:product tuple - the uevent file in that directory contains a PRODUCT=vendor/product/revision (all in hex form without leading zeros).ī) look for any subdirectories which contain a dev file, then get the device name from the DEVNAME= entry from the uevent file in that subdirectory.
# output order is random due to multiprocessing so sort resultsĮcho "$")" \ # wait then gives a chance for all of the iterations to complete )& # & here is causing all of these queries to run simultaneously $0 \"FTDI_FT232\" - will show /dev/ttyUSBX for a device usingįor sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev ) do With no arguments $0 prints information for allĮ.g. SearchString Print only /dev/ of matching output #!/bin/bashĮcho "Find which USB devices are associated with which /dev/ nodes I added shell process backgrounding to make it run a bit faster for lots of USB devices connected to a system (which when this is most useful). I found accepted answer regularly helpful and turned it into a bash script. More filtering of things that aren't actual devices.
LINUX LSUSB COMMAND CODE
This is also the reason why we wrap the code in the parenthesis, so that we use a subshell, and the variables get wiped on each loop. The udevadm info -q property -export command lists all the device properties in a format that can be parsed by the shell into variables. The exit exits the subshell, which flows to the next iteration of the loop. Otherwise you'll get things like USB controllers & hubs. This filters out things which aren't actual devices. This gives us the path in /dev that corresponds to this /sys device. We want the directory path, so we strip off /dev. So we search for directories matching this criteria.
dev/input/event4 - Logitech_HID_compliant_keyboardĮxplanation: find /sys/bus/usb/devices/usb*/ -name devĭevices which show up in /dev have a dev file in their /sys directory. dev/input/event3 - Logitech_HID_compliant_keyboard dev/input/mouse0 - Razer_Razer_Diamondback_3G dev/input/event2 - Razer_Razer_Diamondback_3G dev/input/mouse1 - Logitech_USB_Receiver dev/input/event5 - Logitech_USB_Receiver dev/sdb1 - Lexar_USB_Flash_Drive_AA26MYU15PJ5QFCL-0:0 dev/sdb - Lexar_USB_Flash_Drive_AA26MYU15PJ5QFCL-0:0 On my system, this results in the following: /dev/ttyACM0 - LG_Electronics_Inc._LGE_Android_Phone_VS930_4G-991c470 #!/bin/bashįor sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev) doĭevname="$(udevadm info -q name -p $syspath)"Įval "$(udevadm info -q property -export -p $syspath)" If we don't, you'll see a lot of things in the list that aren't physical devices. Typically only real USB devices will have this attribute, and so we can filter with it. So this answer is about finding the dev path for each device.īelow is a quick and dirty script which walks through devices in /sys looking for USB devices with a ID_SERIAL attribute. You mention 'port' several times, but then in your example, you say the answer is /dev/ttyUSB0, which is a device dev path, not a port. I'm not quite certain what you're asking.