Suppress filename from output of sha512sum

11,624

Solution 1

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/  -//'

Solution 2

sha512sum testfile | awk '{print $1}'

Solution 3

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.

Share:
11,624

Related videos on Youtube

BowPark
Author by

BowPark

Updated on September 18, 2022

Comments

  • BowPark
    BowPark over 1 year

    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>
    
    • cuonglm
      cuonglm about 8 years
      You need help from other tools, like sha512sum testfile | awk '{print $1}'
  • cuonglm
    cuonglm about 8 years
    You need to quote $1, otherwise, you provide security holes in your function unix.stackexchange.com/q/171346/38906