base64
Encode or decode base64 data
TLDR
Encode a file
Wrap encoded output at a specific width (0 disables wrapping)
Decode a file
Encode from stdin
Decode from stdin
SYNOPSIS
base64 [OPTION]... [FILE]
If FILE is not specified or is '-', base64 reads from standard input.
PARAMETERS
-d, --decode
Decodes the input data from Base64 to binary.
-i, --ignore-garbage
When decoding, ignores non-alphabet characters, which can be useful for malformed input or data mixed with other text.
-w, --wrap=COLS
Wraps encoded output lines after COLS characters. A value of 0 disables line wrapping entirely.
--help
Displays a help message and exits.
--version
Displays version information and exits.
DESCRIPTION
The base64 command is a fundamental utility used for encoding and decoding data using the Base64 encoding scheme. Base64 is a binary-to-text encoding method that represents binary data (such as images, executable files, or encrypted data) in an ASCII string format. This conversion is crucial for safely transmitting data over mediums that are designed to handle text, such as email systems, URLs, or when embedding binary data directly into source code or configuration files without corruption. The base64 command typically reads input from standard input or a specified file, performs the encoding or decoding operation, and then writes the result to standard output. It is often piped with other commands for data manipulation, for instance, encoding an image file before embedding it in a JSON payload, or decoding a Base64 string received from a network stream. As part of the GNU Coreutils package, it is widely available and a standard tool on Linux systems.
CAVEATS
Base64 encoding increases the size of the data by approximately 33%, which can impact storage and transmission efficiency. It is an encoding scheme, not an encryption method, meaning the encoded data is not secure and can be easily decoded by anyone with access to the `base64` utility. When handling text files, ensure character encoding (e.g., UTF-8) is consistent to avoid unexpected results, though `base64` primarily operates on raw bytes.
USAGE EXAMPLES
Here are some common usage scenarios for the base64 command:
Encoding a string:echo "My secret data" | base64
Decoding a Base64 string:echo "TXkgc2VjcmV0IGRhdGEK" | base64 -d
Encoding a binary file:base64 photo.png > photo.b64
Decoding a Base64 file:base64 -d photo.b64 > photo_decoded.png
Encoding with no line wrapping (useful for URLs or single-line output):base64 -w 0 binary_blob.bin
HISTORY
The Base64 encoding scheme itself has roots in earlier binary-to-text encoding methods. The base64 command, as part of the GNU Coreutils package, provides a standardized and widely available implementation conforming to RFC 4648 (which defines 'Base64 Data Encodings'). Its widespread adoption on Linux systems makes it a de-facto standard for shell-based Base64 operations, largely replacing older utilities like uuencode for general-purpose binary data encoding/decoding tasks due to its simplicity and adherence to modern standards.