base64
Linux base64 command is encode or decode the string or file. There is a slight difference between base32 and base64, base64 includes the letters A-Z, a-z, numbers 0-9, and the symbols + and /
Below description with examples will explain on how to use this command.
DEFINITION
base64 - base64 encode/decode data and print to standard output
USAGE
base64 [OPTION]... [FILE]
DESCRIPTION
Base64 encode or decode FILE, or standard input, to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-d, --decode
decode data
-i, --ignore-garbage
when decoding, ignore non-alphabet characters
-w, --wrap=COLS
wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping
--help display this help and exit
--version
output version information and exit
The data are encoded as described for the base64 alphabet in RFC 4648. When decoding, the input may
contain newlines in addition to the bytes of the formal base64 alphabet. Use --ignore-garbage to at‐
tempt to recover from any other non-alphabet bytes in the encoded stream.
EXAMPLES
#below command can be used to encode a string using echo
root@letusstudy:/var/log# echo "hello" | base64
aGVsbG8K
#below command can be used to decode a string
root@letusstudy:/var/log# echo aGVsbG8K |base64 --decode
hello
You
#In this example, we will decode dpkg.log file
root@letusstudy:/var/log# head dpkg.log
2020-07-31 16:27:13 startup archives install
2020-07-31 16:27:13 install base-passwd:amd64 <none> 3.5.47
2020-07-31 16:27:13 status half-installed base-passwd:amd64 3.5.47
2020-07-31 16:27:13 status unpacked base-passwd:amd64 3.5.47
2020-07-31 16:27:13 configure base-passwd:amd64 3.5.47 3.5.47
2020-07-31 16:27:13 status half-configured base-passwd:amd64 3.5.47
2020-07-31 16:27:13 status installed base-passwd:amd64 3.5.47
2020-07-31 16:27:14 startup archives install
2020-07-31 16:27:14 install base-files:amd64 <none> 11ubuntu5
2020-07-31 16:27:14 status half-installed base-files:amd64 11ubuntu5
#Below command will encode dpkg.log to dpkg_base64.log
root@letusstudy:/var/log# base64 dpkg.log > dpkg_base64.log
#Encoded file
root@letusstudy:/var/log# head dpkg_base64.log
MjAyMC0wNy0zMSAxNjoyNzoxMyBzdGFydHVwIGFyY2hpdmVzIGluc3RhbGwKMjAyMC0wNy0zMSAx
NjoyNzoxMyBpbnN0YWxsIGJhc2UtcGFzc3dkOmFtZDY0IDxub25lPiAzLjUuNDcKMjAyMC0wNy0z
MSAxNjoyNzoxMyBzdGF0dXMgaGFsZi1pbnN0YWxsZWQgYmFzZS1wYXNzd2Q6YW1kNjQgMy41LjQ3
CjIwMjAtMDctMzEgMTY6Mjc6MTMgc3RhdHVzIHVucGFja2VkIGJhc2UtcGFzc3dkOmFtZDY0IDMu
NS40NwoyMDIwLTA3LTMxIDE2OjI3OjEzIGNvbmZpZ3VyZSBiYXNlLXBhc3N3ZDphbWQ2NCAzLjUu
NDcgMy41LjQ3CjIwMjAtMDctMzEgMTY6Mjc6MTMgc3RhdHVzIGhhbGYtY29uZmlndXJlZCBiYXNl
LXBhc3N3ZDphbWQ2NCAzLjUuNDcKMjAyMC0wNy0zMSAxNjoyNzoxMyBzdGF0dXMgaW5zdGFsbGVk
IGJhc2UtcGFzc3dkOmFtZDY0IDMuNS40NwoyMDIwLTA3LTMxIDE2OjI3OjE0IHN0YXJ0dXAgYXJj
aGl2ZXMgaW5zdGFsbAoyMDIwLTA3LTMxIDE2OjI3OjE0IGluc3RhbGwgYmFzZS1maWxlczphbWQ2
NCA8bm9uZT4gMTF1YnVudHU1CjIwMjAtMDctMzEgMTY6Mjc6MTQgc3RhdHVzIGhhbGYtaW5zdGFs
root@letusstudy:/var/log#
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report base64 translation bugs to <https://translationproject.org/team/>
COPYRIGHT
Copyright © 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the ex‐ tent permitted by law.
No Comments