Enumerate USB block devices in a different way than described in How to enumerate USB block devices (USB memory and HDD).
ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$'
You can get a list of USB block devices and a symbolic link to their real device by running / dev/disk/by-id/usb *
.
$ ls /dev/disk/by-id/usb* -l
lrwxrwxrwx 1 root root 9 December 27 21:28 /dev/disk/by-id/usb-BUFFALO_USB_Flash_Disk_xxxxxxxxx-0:0 -> ../../sdb
lrwxrwxrwx 1 root root 10 December 27 21:28 /dev/disk/by-id/usb-BUFFALO_USB_Flash_Disk_xxxxxxxxx-0:0-part1 -> ../../sdb1
Since you can get the entity of the symbolic link by readlink -f
, you can get the list of the entity of the USB block device below.
$ ls /dev/disk/by-id/usb* -1 | xargs readlink -f
/dev/sdb
/dev/sdb1
Device files for partitions such as / dev/sdb1
are also displayed, so use grep to filter using regular expressions.
$ ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$'
/dev/sdb
Recommended Posts