This is an incremental improvement on Vouze's answer to make the output of the script look exactly like the normal output of GNU's
The following version of
tarhash.sh handles the situation where the filename contains a newline or backslash in the same way that the current version of
sha1sum/... does, in case that turns out to be necessary. It also preserves the two spaces between the sum and the filename (or the single space and
*, if you change the command from
As long as the filenames are sorted in the same way (or if you sort both sides first), the output of this script can be compared to an original
sha1sum output using your favorite diff tool.
(echo -n "`sha1sum`" | sed 's/-$//' && echo -n "$TAR_FILENAME") |
sed -z 's/\\/\\\\/g; s/\n/\\n/g; /\\/ s/^/\\/; s/$/\n/;'
# Note: In this tar invocation, make sure not to specify -v
# (The output comes out wrong if it is included).
tar xJf myArchive.tar.xz --to-command=./tarhash.sh > sha1sums.txt