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.

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");'

An alternative, hackier, approach is discussed in my post on LTO tape drives:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.