3

After plugging the USB to the port of my machine, if I do lsusb I see the device I am looking for:

Bus 001 Device 004: ID 04f2:b573 Some Manufacturer

If I list the devices under /dev/, I can see lots of device paths, such as /dev/tty0, /dev/ttyUSB0... etc. For what I understand, one of these paths will be my USB device, or be where my USB device is connected to.

How do I know which one is the one with the ID 04f2:b573?


This question is similar to mine, however (referring to the accepted answer) I don't know what exactly is $ID_SERIAL, or how to I set it to be equal to the Id I'm looking for, or even what is the correct path (since his example shows multiple device paths, such as /dev/ttyACM0, /dev/sdb, /dev/input/event5 ...)

Also, the second answer assumes that I know the device is connected to /dev/ttyUSB0, which I don't know beforehand (testing it on this specific path gives me no device, by the way).

2

How do I know which one is the one with the ID 04f2:b573?

There may be better ways to do it, but a quick and dirty way to do it is with:

find_by_id(){
    v=${1%:*}; p=${1#*:}  # split vid:pid into 2 vars
    v=${v#${v%%[!0]*}}; p=${p#${p%%[!0]*}}  # strip leading zeros
    grep -il "^PRODUCT=$v/$p" /sys/bus/usb/devices/*:*/uevent |
    sed s,uevent,, |
    xargs -r grep -r '^DEVNAME=' --include uevent
}
find_by_id 04f2:b573

My old Huawei phone appears as two serial ttys:

$ find_by_id 12d1:
/sys/bus/usb/devices/3-1:1.0/ttyUSB0/tty/ttyUSB0/uevent:DEVNAME=ttyUSB0
/sys/bus/usb/devices/3-1:1.1/ttyUSB1/tty/ttyUSB1/uevent:DEVNAME=ttyUSB1

You can change the last grep to

xargs -r egrep -rB2 '^DEVNAME=|^IFINDEX=' --include uevent

in order to also find the usb network interfaces:

$ find_by_id 0e8d:
/sys/bus/usb/devices/1-6.2.3:1.0/net/usb0/uevent-INTERFACE=usb0
/sys/bus/usb/devices/1-6.2.3:1.0/net/usb0/uevent:IFINDEX=10

$ find_by_id 03f0:
/sys/bus/usb/devices/1-6.3:1.1/usbmisc/lp1/uevent-MAJOR=180
/sys/bus/usb/devices/1-6.3:1.1/usbmisc/lp1/uevent-MINOR=1
/sys/bus/usb/devices/1-6.3:1.1/usbmisc/lp1/uevent:DEVNAME=usb/lp1
1
  • I thought there would be an easier way but this worked, thanks! – Bersan Feb 12 '20 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.