To base64 encode or decode a string in macOS Terminal console you can make use of base64 command.
Examples:1. Encode to Base64 String:
mac ~ % base64 <<< "Hello World - This is my String"
SGVsbG8gV29ybGQgLSBUaGlzIGlzIG15IFN0cmluZwo=
You can also concatenate two commands like an echo to get the encoded string,
mac ~ % echo "Hello World" | base64
SGVsbG8gV29ybGQK
2. Decode Base64 String to Text:
If you have a base64 encoded string and you want to decode it to plain string, you can make use of -D option,
mac ~ % base64 -D <<< "SGVsbG8gV29ybGQgLSBUaGlzIGlzIG15IFN0cmluZwo="
Hello World - This is my String
3. Encode a file:
If you want to encode a file, you can do that by using -i option
mac Desktop % base64 -i myFile.txt
SGVsbG8gdGhlcmUhClRoaXMgaXMgbXkgZmlsZSBpIHdhbnQgdG8gZW5jb2RlLg==

Terminal Base64 Command - Files
4. Write encoded/decoded string to a file:
Now let's see how we can read a string from a file and write to another file, to write a file we can make use of -o option,
The best way to know more about this command is by checking the manual,
% base64 -i myFile.txt -o myOutput.txt
Some related links:
More Posts related to MacOS,
- How to Display Analog Clock on Mac Menu Bar
- Shutdown Mac Terminal Command
- How to know the Serial Number of MacBook on macOS Ventura 13.0
- macOS: Remove Desktop or Documents Folder from iCloud Drive Syncing
- [fix] How to Show file extensions on all files on Mac
- How to install Zoom Add-in to Outlook (Mac)
- How to turn off Stage Manager - macOS Ventura
- Fix - Xode - Internal logic error: Connection was invalidated
- How to do calculations in Mac Terminal
- How to delete a Page in Microsoft Word File on Mac (macOS)
- How to Refresh Mac Desktop
- How to install Java on macOS [Big Sur]
- How to Disable Mac Terminal Bell Sound
- Installing MongoDB on Linux/Unix/macOS/Ubuntu
- How to Uninstall Brew on Mac
- Find your macOS version
- Change TextEdit File Encoding
- AppleScript Example with TextEdit
- How to install homebrew (brew) on M1 Mac
- How to Find File and Directory Size in Mac Terminal
- How to open new tab in Sublime Text Editor [macOS]
- How to list all users in Mac Terminal
- Turn off Auto-Capitalization on macOS Ventura 13
- How to check Command Line Tools Version [Updated for Ventura]
- Change Current User Password using Mac Terminal Command
More Posts:
- cURL DELETE Request with Examples - cURL
- [Android Studio] Button on click example - Android-Studio
- How to Show Battery Percentage inside iPhone 12-14 Battery Indicator? - iOS
- Fix MySQL - Error: (OperationalError) (HY000) [08S01] Communications link failure - MySQL
- Eclipse : Workspace was written with an older version of the product and will be updated - Eclipse
- Tkinter - add x and y padding to label text - Python
- Tutorial Java SOAP WebServices JAS-WS with Eclipse J2EE IDE and Tomcat Server Part 1 - Java
- How to Refresh Mac Desktop - MacOS