macOS Terminal – How to Get Dev Name Associated with Volume Name

bashmacosscriptterminal

I am creating a bash script to unmount my usb drive after the backup is done.
To unmount the drive I use the command:

diskutil unmount disk4s1

But sometimes when I plug my usb drive it gets a different dev name, as disk3s1, or disk2s1.
I need add a line in my script before unmount the disk, to get the dev name associated to my volume name.

What command could I use to get the dev name given its volume name?

Best Answer

mount | grep /Volumes/foo | cut -d ' ' -f1

or

mount | awk '/Volumes\/foo/ { print $1 }'