formats

Encode or Decode base64 from the Command Line

Published on September 1, 2012, by + in linux.




If you have ever needed to quickly decode or encode base64, Linux has a command line utility called base64 that works great. I’ll show you how it works!


To encode text to base64, use the following syntax:

$ echo 'scottlinux.com rocks' | base64
c2NvdHRsaW51eC5jb20gcm9ja3MK



To decode, use base64 -d. To decode base64, use a syntax like the following:

$ echo c2NvdHRsaW51eC5jb20gcm9ja3MK | base64 -d
scottlinux.com rocks



Note: if on OS X, use capital D:

echo c2NvdHRsaW51eC5jb20gcm9ja3MK | base64 -D

Cool!

One Response

  1. C

    use “echo -n” to prevent the newline from echo being encoded in the result as well.

    echo -n “blah” | base64

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home linux Encode or Decode base64 from the Command Line