Ubuntu – Write the output of multiple sequential commands to a text file

bashcommand line

I try to Check the latest Firefox and want to get all hashes in one TXT file.

What I try to do is:

sha1sum firefox.tar.gz > sha.txt

and I try also:

md5sum firefox.tar.gz > sha.txt | sha1sum firefox.tar.gz > sha.txt | sha512sum firefox.tar.gz > sha.txt 

but only the last in this case the sha512 is printed to the sha.txt.

What am I doing wrong? Please can someone out there help me with this?

Best Answer

As others have already pointed out the difference between > (overwrite) and >> (append) redirection operators, i am going to give couple of solutions.

  1. You can use the command grouping {} feature of bash to send the output of all the commands in a single file :

    { sha1sum foo.txt ;sha512sum foo.txt ;md5sum foo.txt ;} >checksum.txt
    
  2. Alternately you can run the commands in a subshell () :

    ( sha1sum foo.txt ;sha512sum foo.txt ;md5sum foo.txt ) >checksum.txt
    
Related Question