The base64
command is used to encode or decode binary data in Base64 format. It is primarily used to encode binary data so that it can be transmitted over channels that are designed to handle textual data. The base64
command can be used to encode or decode files or standard input/output.
Overview
The base64
command can be used to encode or decode files or standard input/output. The basic syntax for the base64
command is as follows:
base64 [OPTION]... [FILE]
If no file is specified, base64
will read from standard input. If no option is specified, base64
will encode the input.
To encode a file, use the -w
option to specify the maximum line width (default is 76 characters):
base64 -w 0 file.txt > file.txt.b64
To decode a file, use the -d
option:
base64 -d file.txt.b64 > file.txt
Options
The following table lists all available options for the base64
command:
Option | Description |
---|---|
-d , --decode |
Decode data |
-i , --ignore-garbage |
When decoding, ignore non-alphabet characters |
-w , --wrap=COLS |
Wrap encoded lines after COLS characters (default 76). Use 0 to disable line wrapping |
-h , --help |
Display help message and exit |
-v , --version |
Output version information and exit |
Troubleshooting tips
- If you encounter errors while decoding, try using the
-i
option to ignore non-alphabet characters. - If you encounter errors while encoding, try increasing the maximum line width using the
-w
option.
Notes
- Base64 encoding is not a form of encryption and should not be used to protect sensitive data.
- Base64 encoding increases the size of the data by approximately 33%.