Get device name of the newest usb-thumb-drive in the system

Thursday, 2. February 2012

this post is just a note to myself (like many others on this blog)

ls -t /dev/sd* | head -1 | /bin/sed -e 's/^\/dev\/*//' |cut -c 1-3
 

i had to figure out a way to determine the name of the usb-thumb-drive i JUST connected within a script – well.. it works but im open for suggestions 🙂

first i list all devices that begin with “sd” sorted by creation time/date 

then i filter the newest device and cut off  the string “/dev/”

at last i cut the first 3 letters of the string because that’s all i need (i do not need to know the partition number of the device)

One Response to “Get device name of the newest usb-thumb-drive in the system”



  1. Imelda Engl Says:

    Mike,I’m having the same problem, have used many players, all the same.Did you find a solution?Phil