How to enumerate USB block devices (USB memory and HDD) (Part2)

How to enumerate USB block devices (USB memory and HDD) (Part2)

Enumerate USB block devices in a different way than described in How to enumerate USB block devices (USB memory and HDD).

Method

ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$'

Commentary

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

How to enumerate USB block devices (USB memory and HDD) (Part2)
How to enumerate USB block devices (USB memory sticks and HDDs)
How to use Python zip and enumerate
How to block ads for free on iPhone and iPad apps
How to use Python with Jw_cad (Part 2 Command explanation and operation)
How to install and use Tesseract-OCR
How to install and configure blackbird
How to use .bash_profile and .bashrc
How to install CUDA and nvidia-driver
How to install and use Graphviz
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to solve slide puzzles and 15 puzzles
[Python] How to use the enumerate function (extract the index number and element)
[Linux] How to subdivide files and folders
How to package and distribute Python scripts
How to use cybozu.com developer network (Part 2)
How to split and save a DataFrame
How to install and use pandas_datareader [Python]
How to use Tweepy ~ Part 1 ~ [Getting Tweet]
[Cocos2d-x] How to make Script Binding (Part 2)
python: How to use locals () and globals ()
How to make multi-boot USB (Windows 10 compatible)
[Python] How to calculate MAE and RMSE
[Cocos2d-x] How to make Script Binding (Part 1)
How to use is and == in Python
How to use pandas Timestamp and date_range
How to install fabric and basic usage
How to write pydoc and multi-line comments