22

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

<hash_code>
BowPark
  • 4,895

4 Answers4

24

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/  -//'
Anthon
  • 79,293
7
sha512sum testfile | awk '{print $1}'
don_crissti
  • 82,805
Kurian
  • 81
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,

sha()
{
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.

  • 1
    You need to quote $1, otherwise, you provide security holes in your function http://unix.stackexchange.com/q/171346/38906 – cuonglm Feb 25 '16 at 14:07
-1

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

sha512sum | tr " " "\n" | head -n 1
jasonwryan
  • 73,126