I have a SCSI tape (/dev/st0) and I would like to get information about how much of it is used.
How can I do that, preferably with a command?
if it's a LTO or other tape with auxiliary memory:
sg_logs -a /dev/sgX
where sgX is the SCSI-generic device corresponding to your tape drive (
sg_scan may help you find it, if you don't already know it from e.g., tape alert checking)
The way modern tape drives work, you can't know how much of the tape is used without reading it.
Tapes are simple character devices with rewind capability, so when writing, the tape puts an EOM marker when the write is completed, then rewinds. When when reading, it will rewind the tape, then it simply reads the entire tape until it hits the EOM.
So you can do a
dd if=/dev/st0 of=/dev/null
dd completes (with an error since it will try read past EOM) it will tell you the amount of data it read.
If you know the tape has megabytes of data, and are willing to be off a megabyte, adding
bs=1M will make this go faster- - it will try to read 1M at a time instead a byte at a time.