Maybe it is a trivial question, but in the man page I didn't find something useful. I am using Ubuntu and bash.

The normal output for sha512sum testfile is

<hash_code>  testfile

How to suppress the filename output? I would like to obtain just

  • 2
    You need help from other tools, like sha512sum testfile | awk '{print $1}'
    – cuonglm
    Feb 25, 2016 at 13:48

4 Answers 4


There isn't a way to suppress that, but since the SHA is always a single word without spaces you can do:

sha512sum testfile | cut -d " " -f 1 

or e.g.

< testfile sha512sum | sed 's/  -//'
sha512sum testfile | awk '{print $1}'

Maybe just add an alias in your ~/.profile per the Anthon's way of cutting the first argument would help as a permanent solution,

sha512sum -- "$1" | cut -d " " -f 1

To get it working, we obviously would need to run it once as, . .profile in ~.

Now putting only sha <file_name> would yield the way you wish it.


I also was frustrated by sha??sum stdout format, I used;

sha512sum | tr " " "\n" | head -n 1

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.