Encode or Decode base64 from the Command Line

By | 2012/09/01

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 -n 'scottlinux.com rocks' | base64

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

$ echo -n c2NvdHRsaW51eC5jb20gcm9ja3MK | base64 -d
scottlinux.com rocks

Note: if on OS X, use capital D:
echo -n c2NvdHRsaW51eC5jb20gcm9ja3MK | base64 -D