base64 Command in Linux with Examples

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

advertisement
advertisement

-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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
$ 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

advertisement
$ 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

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

advertisement
If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.