Hash files in tar file

If it's GNU tar, run this:

tar -xf file1.tar --to-command=file-stats-from-tar

where file-stats-from-tar is somewhere in $PATH and is:

#!/bin/bash

md5=`md5sum`;
md5=${md5%% *}

printf "%s\t%s\n" $md5 "$TAR_FILENAME"

Change md5sum if you need to.

This does it all in a single pass.

How it works is that the --to-command option tells tar to send each file separately to the command you specify, with a bunch of environment variables set (we only use TAR_FILENAME here).

Tags:

Tar