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 '16 at 13:48

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/  -//'
|improve this answer|||||
sha512sum testfile | awk '{print $1}'
|improve this answer|||||

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.

|improve this answer|||||

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

sha512sum | tr " " "\n" | head -n 1
|improve this answer|||||

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.