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?

2 Answers 2

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


mount | awk '/Volumes\/foo/ { print $1 }'
  • Thank you!. This is my bash code to unmount myvolume working perfect now : devname=$(mount | grep /Volumes/myvolume | cut -d ' ' -f1); osascript -e 'do shell script "diskutil unmount '$devname'" '
    – bunset
    May 28, 2016 at 22:15

You can just use the volume name with diskutil though, there's no need to get the identifier:

$ diskutil unmount VolumeName
Volume VolumeName on disk1s1 unmounted

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .