First, my thanks to all who contributed. I learned a few useful things.
Still, my experience is that most of these answers are somewhat
incomplete, at least where CD and DVDs are concerned,
notably regarding whether they are available to normal users
rather than restricted to the superuser.
This is based on tests on my Linux Mageia 2.
Commands intended for the superuser can always be accessed by a normal
user by prefixing them with /sbin/, or sometimes with /usr/sbin/.
Now they may or may not work for a normal user.
Many may work, for a normal user, for a DVD on the DVD drive, even when it is not mounted, while they will not work for a hard disk (again when invoked as normal user).
For example /sbin/fdisk -l /dev/cdrom will work on my system and
give the "geometry" of the DVD in the drive ... which is apparently
mostly nonsense. But it does give the size of the DVD in bytes and in
sectors, and a correct sector size (of 2048 bytes as is usual for DVD).
The same is true of /usr/sbin/gdisk -l /dev/cdrom, which give only
the size in sectors of 2048 bytes.
other examples (as non-root, normal user)
$ /sbin/blockdev --getss /dev/cdrom # DVD sector size
2048
$ /sbin/blockdev --getsize64 /dev/cdrom # DVD byte size
5453316096
$ cat /proc/partitions # see below
...
8 8 416027241 sda8
11 0 5325504 sr0
8 16 1465138584 sdb
...
This works for the DVD drive, here called sr0, since the device for it
is actually /dev/sr0, /dev/cdrom being only a symbolic link to it.
The size is given in chunks of 1k.
Similarly, as normal user, the command
$ cat /sys/class/block/sr0/size
10651008
will give the size of a DVD on device /dev/sr0, in chunks of 512k512 bytes
(as well as the size of other disk, even not mounted).
However cat /sys/class/block/cdrom/size will not work be cause
/dev/cdrom is only a symbolic link
The command df, suggested by some, gives the size of mounted
partitions, not of whole disks. Furthermore, for a mounted CD or DVD
it gives less than the actual size of the CD/DVD. More precisely, there are
two distinct sizes one may be interested in :
- the overall size of the device, including what is used for its internal organization. Typically that is the size of the file obtained if it is copied whole with the command
dd; - the size of the space available (possibly only in read-only mode) to the user when it is mounted, which is always less. That is the size that is indicated by the command
df.