I've just built a script for that, it's not pretty but works for me.
I tested this script on Arch Linux with this configurations:
$ uname -a
Linux 4.4.13-1-lts #1 SMP Wed Jun 8 16:44:31 CEST 2016 x86_64 GNU/Linux
And my device name is /dev/sdb
which is quite different from yours, I hope
it will work for you as well.
Also note that this script depends on usbutils
package for usb-devices
program, I believe its installed by default on all linux, but i might be wrong.
Script usbname
:
#!/usr/bin/bash
# Input should be a single line from lsusb output:
DATA=$1
# Read the bus number:
BUS=`echo $DATA | grep -Po 'Bus 0*\K[1-9]+'`
# Read the device number:
DEV=`echo $DATA | grep -Po 'Device 0*\K[1-9]+'`
FOUND=false
USB_Serial=""
# Search for the serial number of the PenDrive:
while read line
do
if [ $FOUND == true ]; then
USB_Serial=`echo "$line" | grep -Po 'SerialNumber=\K.*'`
if [ "$USB_Serial" != "" ]; then
break;
fi
fi
if [ "`echo "$line" | grep -e "Bus=0*$BUS.*Dev#= *$DEV"`" != "" ]; then
FOUND=true
fi
done <<< "$(usb-devices)"
# Get the base name of the block device, e.g.: "sdx"
BASENAME=`file /dev/disk/by-id/* | grep -v 'part' | grep -Po "$USB_Serial.*/\K[^/]+$"`
# Build the full address, e.g.: "/dev/sdx"
NAME="/dev/$BASENAME"
# Output the address:
echo $NAME
Usage:
$ ./usbname "$(lsusb | grep '<my_usb_label_or_id>')"
/dev/sdb
/dev/disk/
, the by-label and by-id paths might be of use. – lornix Jun 13 '14 at 09:54/dev/disk
contains only storage devices. Say, there's nothing about/dev/ttyUSB0
. – Dmitry Frank Jun 13 '14 at 17:58/dev/ttyUSB0
etc? – Faheem Mitha Apr 01 '16 at 09:39