This tutorial explains Linux “base64” command, options and its usage with examples.
base64 – base64 encode/decode data and print to standard output.
DESCRIPTION
Base64 encode or decode FILE, or standard input, to standard output.
SYNOPSIS
base64 [OPTION] [FILE]
OPTIONS
-w, –wrap=COLS
Wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping.
-d, –decode
Decode data.
-i, –ignore-garbage
When decoding, ignore non-alphabet characters.
EXAMPLES
1. To encode text to base64, use the following
$ echo ‘this is sanfoundry linux tutorial’ | base64
dGhpcyBpcyBzYW5mb3VuZHJ5IGxpbnV4IHR1dG9yaWFsCg==
2. To decode, use base64 -d.
$ echo ‘dGhpcyBpcyBzYW5mb3VuZHJ5IGxpbnV4IHR1dG9yaWFsCg==’ | base64 -d
this is sanfoundry linux tutorial
3. Wrap lines while encoding using -w option
$ echo ‘this is sanfoundry linux tutorial’ | base64 -w 10
dGhpcyBpcy
BzYW5mb3Vu
ZHJ5IGxpbn
V4IHR1dG9y
aWFsCg==
Here i have wrapped the output to line characters per line.
4. base64 encode and decode a file
$ cat file1.txt
abc
def
ghi
$ base64 file1.txt
YWJjCmRlZgpnaGkK
$ echo ‘YWJjCmRlZgpnaGkK’ | base64 -d
abc
def
ghi