Base64 decode on the command line

There are several options to decode a base64-encoded file on the command line, or vice-versa, encode some text to base64. base64 is probably the easiest command to use and easiest to remember, however, it might not be available on every system. In that case the other two options are viable alternatives.


(install with sudo apt-get install coreutils)

Encode/Decode: base64 [-d / -e] infile outfile

Use -d for decode.
Use -e for encode.
Both infile and output can be ‘-‘, meaning that the input will be read from stdin, and/or the output will be written to stdout, respectively.

perl one-liner (found here)

(install with sudo apt-get install perl)

Encode: perl -MMIME::Base64 -ne 'print encode_base64($_)' < infile > outfile
Decode: perl -MMIME::Base64 -ne 'print decode_base64($_)' < infile > outfile


(install with sudo apt-get install openssl)

Encode: openssl enc -base64 -in infile -out outfile
Decode: openssl enc -d -base64 -in infile -out outfile