A quick way to get a MD5 hash of a string in Linux CLI

the simples way to get a MD5 hash of a string that I found is:

md5sum<<<putYourWordHere

this should print:

074d876a127bc3344f9c3c72cefac56d  -

Unfortunately this will print the hash followed by trailing two spaces and a dash.
To get rid of them, simply pipe the output to the cut command:

md5sum<<<putYourWordHere | cut -f1 -d' '

this will print the hash without that trailing garbage

074d876a127bc3344f9c3c72cefac56d

Finally, if you'd like to convert it into a bash command, the add this function to you .bashrc file

# will calculate md5sum from a input string
# example 1: md5 "this is a long string test_string"
# example 2: md5 singleWordExample
function md5() { md5sum<<<$1 | cut -f1 -d' '; }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s