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]Related Posts:
- Check Linux Books
- Practice Programming MCQs
- Apply for Programming Internship
- Check Information Technology Books