Bash – Read the title from a DVD

bashdvd

I've noticed that each DVD image has a semi-unique uppercase name. Is there a standardized way for me to simply read this name as a non-root user in Linux? I'm on an Ubuntu 12.04 derivative running kernel 3.7. I'd like to simply get the name of any disk currently in the drive like so:

DVD_NAME="$( ./read-dvd-name.sh )"

Best Answer

You could use blkid for that:

DVD_NAME=$(blkid -o value -s LABEL /dev/dvd)

(you need to have read permission to /dev/dvd for that).

Or:

DVD_NAME=$(udevadm info -n dvd -q property | sed -n 's/^ID_FS_LABEL=//p')

for which you don't need any special privilege (udev (running as root) queries the label name using blkid and updates a device database which you query with udevadm).

Related Question