9

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 )"
Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311

2 Answers2

17

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

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
1

I am not sure whether this would help you:

isoinfo  -i C462_19-08-26_09-56.iso -d | sed -n 's/^Volume id: //p'
isoinfo  -i C462_19-08-26_09-56.iso -d | awk '/Volume id: / {print $3}'

My clumsy original solution:

dvdtitle=$(isoinfo  -i isofile.iso -d | grep "Volume id:" | awk '{print $3}')
xerostomus
  • 339
  • 3
  • 6
  • 2
    (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 Says 'Reinstate Monica' Oct 02 '15 at 18:56
  • 2
    (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 Says 'Reinstate Monica' Oct 02 '15 at 18:59
  • Dear G-Man, thank you for you valuable hints. :-) Sincerely X. – xerostomus Nov 06 '19 at 16:16