tee command, show both stdout outputs

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 likef=filename; sudo cat $f; sudo cksum $fbut I would prefer to use tee or sth similar if possible.

2 Answers

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 $_

2

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

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like