1

if i run the common lsusb i get something like:

Bus 003 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

but it doesn't show the device file path (i.e ttyUSB0). does it exist a command which does this?

about dmesg and udevadm info they are too verbose.

I would rather to have a simpler output, the best would be to append just the device file path to the output of lsusb, something like:

Bus 003 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter /dev/ttyUSB0

  • 1
    Please try: lsusb -t – chili555 Aug 27 '18 at 15:31
  • output without port: /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M |__ Port 1: Dev 4, If 0, Class=Vendor Specific Class, Driver=ch341, 12M – aster94 Aug 27 '18 at 15:35
  • 2
    Are you looking for the actual physical port, or the corresponding ttyUSB device path? That isn't the "port", that's the "Device file path" – Thomas Ward Aug 27 '18 at 15:40
  • yes, my mistake (due to ignorance) i am editing my question – aster94 Aug 27 '18 at 15:41
  • 1
    I think dmesg -w is the easy way but check this answer for more options stackoverflow.com/questions/2530096/… – Katu Aug 27 '18 at 16:36
1

a lot of copy/paste brought me again here hoping that this would be helpful for others and also to improve my code

I used the almost perfect code from the answer in this question and added/removed some little stuff

#!/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
        [[ "$devname" == "input/"* ]] && continue
        [[ "$devname" == "video0"* ]] && continue

        eval "$(udevadm info -q property --export -p $syspath)"
        [[ -z "$ID_SERIAL" ]] && continue

        busnum="$(udevadm info -a -p  $(udevadm info -q path -n /dev/$devname) | awk -F "==" '/busnum/ {gsub("\"","");print $2}' | head -1)"
        devnum="$(udevadm info -a -p  $(udevadm info -q path -n /dev/$devname) | awk -F "==" '/devnum/ {gsub("\"","");print $2}' | head -1)"
        bus_dev=${busnum}:${devnum}
        lsusb="$(lsusb -s $bus_dev)"

        echo "$lsusb - /dev/$devname"
    )
done

output:

Bus 003 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter - /dev/ttyUSB0

NOTE: i don't have any unix experience so if you would like to improve the code please do!

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.