I would like to show the content of a file and also the calculated cksum of the file at once, why does the following command only output the file - but not the cksum?

sudo cat filename | tee cksum

I know that I could use sth like f=filename; sudo cat $f; sudo cksum $f but I would prefer to use tee or sth similar if possible.


Didn't you mean:

sudo cat filename | tee file-name | cksum

To repeat the file name, tee is not the command you want.

Try: cat filename && cksum $_

  • I would prefer to avoid the duplication of "filename" since it is a very long path. Otherwise I could simply use cat filename && cksum filename - right? :) – tollo Dec 29 '18 at 16:37
  • tee is not the command you want. To repeat the file name try: cat filename && cksum $_. – harrymc Dec 29 '18 at 16:48

The reason why your command does not show the checksum is because you're actually writing to a file called cksum and printing it to stdout, instead of printing it to stdout and passing it on to the actual chksum command.

What you can do instead is using tee to write it to the tty file (your terminal) and use the stdout for chksum, like the following:

sudo cat filename | tee /dev/tty | cksum

Source from Stackoverflow

  • thank you very much! I like the other solution just a little bit more but yours is also very handy - I will keep it in mind. thanks! – tollo Dec 29 '18 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.