Skip to content

Instantly share code, notes, and snippets.

@ekawahyu
Created June 12, 2023 17:07
Show Gist options
  • Save ekawahyu/1aea4878be0b723a860c17e9a947c23c to your computer and use it in GitHub Desktop.
Save ekawahyu/1aea4878be0b723a860c17e9a947c23c to your computer and use it in GitHub Desktop.
Simple bash script to list of multiple USB serial devices by their name
#!/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/"* ]] && exit
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && exit
echo "/dev/$devname - $ID_SERIAL"
)
done
@ekawahyu
Copy link
Author

Example output:

zorin@zorin-58xxq-02:~$ ./usbdev.sh 
/dev/ttyUSB1 - Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001
/dev/ttyUSB0 - FTDI_FT232R_USB_UART_ABSCGEID
/dev/ttyUSB4 - Quectel_EC25-AF
/dev/ttyUSB2 - Quectel_EC25-AF
/dev/ttyUSB5 - Quectel_EC25-AF
/dev/ttyUSB3 - Quectel_EC25-AF
zorin@zorin-58xxq-02:~$ cat usbdev.sh 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment