8

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 )"
  • 1
    It's bad practice to use all uppercase variable names for non-environment variables. – jordanm Jan 18 '13 at 5:02
  • 5
    Thanks, but this doesn't answer my question :) Bad-practice is debatable. – Naftuli Kay Jan 18 '13 at 6:20
  • 2
    That's why it was a comment and not an answer. – jordanm Jan 18 '13 at 14:38
10

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).

  • Do I need to be root to do that? – Naftuli Kay Feb 1 '13 at 23:57
0

I am not sure whether this would help you:

dvdtitle=$(isoinfo  -i isofile.iso -d | grep "Volume id:" | awk '{print $3}')
  • 1
    (1) The question title is “Read the title from a DVD?” and the last sentence in the question says, “I’d like to simply get the name of any disk currently in the drive …”, so you should probably start off by suggesting isoinfo -i /dev/cdrom -d   …, and then add, as a postscript, the fact that the command can be used to examine an ISO image in a file by specifying …   -i iso_image_filename  .  … (Cont’d) – G-Man Oct 2 '15 at 18:56
  • 1
    (Cont’d) …  (2) awk is a powerful text processing tool; you hardly ever need to use it in conjunction with another text processing tool such as grep.  Your pipeline, grep "Volume id:" | awk '{print $3}', can be simplified to awk '/Volume id: / {print $3}'.  (3) Volume IDs can be multiple words, and this print $3 approach displays only the first one.  There are ways of handling this in awk, but an easier approach is to pipe the output from isoinfo into sed -n 's/Volume id: //p'.  (4) As a sanity check, it would be better to search for /^Volume id: /. – G-Man Oct 2 '15 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.