base64
Text processing
Usage
base64 [file]Turns bytes into ASCII text and back so binary can travel through text-only channels; it is encoding, not encryption, and the decode flag is -d on GNU but -D on older macOS.
Common flags
| Flag | Meaning |
|---|---|
| -d | Decode. GNU and recent macOS take -d; older macOS needs -D |
| -w | GNU: wrap at N columns, and -w0 keeps it on one line |
| -i | GNU: ignore junk while decoding. On macOS -i names the input file |
| -o | BSD and macOS: write to this file |
| -b | BSD and macOS: wrap the encoded output at N characters |
Examples
base64 -w0 cert.pemOne long line, no wrapping (GNU).
echo aGVsbG8= | base64 -dDecodes back to hello.
base64 -i photo.png -o photo.txtEncoding into a file on macOS.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does base64 do?
Turns bytes into ASCII text and back so binary can travel through text-only channels; it is encoding, not encryption, and the decode flag is -d on GNU but -D on older macOS.
Q. How do I type it?
base64 [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man base64. This command sits under Text processing.
Related commands
man page: man base64