Dark's Code Dump

Possibly useful

Print tar label without reading entire tar archive

GNU Tar lacks an option to print the tar label and exit immediately - it can only print the label as part of reading the whole archive. This works ok-ish for hard disks where ctrl+c is instant and without side effects, but is unsuitable for tape drives. EDIT: This is because I had my drive in the wrong mode, see the sysv vs bsd modes.

The following simple perl one-liner prints the label from a tar archive passed in stdin:

cat my.tar | perl -e 'read(STDIN, $header, 100); print(unpack("Z100", $header)."\n");'

Sometimes you get weird shit at the start of tar archives like '/tmp/GlobalHead', in which case you can use this hacky alternative approach:

cat my.tar | strings | grep volume.label | cut -d \= -f2

You can see a use case for this in my post on LTO tape drives: https://darkimmortal.com/2018/10/adventures-with-lto-tape-for-home-casual-use/

Leave a Reply