0

Say I copy a file with pv, is there any way to also get any hash, like md5, sha1, etc without having to read origin twice? It has to work with big files or block devices.

Example command which does not work as expected:

pv /dev/sda1 | tee md5sum > /mnt/backups/sda.backup
0

1 Answer 1

3

... | tee md5sum > outputfile doesn't work because tee takes a filename as argument, the command would create a file called md5sum. Instead, you could replace the filename with a process substitution (in Bash/ksh/zsh):

... | tee >(md5sum) > outputfile

or just flip the logic so that you give the destination filename to tee, and can then pipe its stdout to md5sum:

... | tee outputfile | md5sum

Also, you may want to use e.g. sha256sum or sha512sum instead, given how MD5 is known to be rather broken.

1
  • Thanks that's perfect.
    – Smeterlink
    Dec 15, 2021 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .