“base64” Command Usage Examples in Linux

«
»

This tutorial explains Linux “base64” command, options and its usage with examples.

base64 – base64 encode/decode data and print to standard output.

DESCRIPTION

advertisement

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

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

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!
advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter