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,
- Opening mac Terminal
- How to change default macOS Terminal Window size
- How to clear Mac Terminal screen
- Find Hostname of Mac running on macOS Ventura 13
- Installing MongoDB on Linux/Unix/macOS/Ubuntu
- How to switch from bash to zsh shell in macOS Terminal
- Limit scrollback rows in macOS Terminal
- How to Set Background Wallpaper on macOS 13 Ventura
- This operation couldnt be completed. Unable to locate a Java Runtime. [macOS]
- Encode or Decode Base64 String using Mac Terminal Command
- List of All Apple Silicon ARM Based M1/M2 Mac [updated Oct 2022)
- How to remove Siri from Menu Bar [macOS Big Sur]
- Must Know Homebrew Commands for Mac/Linux Users
- Hide Keyboard Text Input Icon on macOS Ventura Menu Bar
- 13.0 MacOS Ventura release date
- How to change the default location of Mac Screenshot
- How to set Out Of Office (OOO) on Outlook for Mac
- 30+ Zoom video communications application shortcuts for macOS
- How to install wget on macOS
- Mac turn dark mode on or off using terminal command
- Create Symbolic Link using Terminal Command
- Mac - How to Install VirtualBox
- How to Enable or Disable Dark Mode on macOS Ventura 13
- How to install homebrew (brew) on M1 Mac
- How to uninstall Microsoft Outlook on Mac
More Posts:
- Implementing Android Text to Speech Example - Android
- How to install Microsoft Outlook App on Mac - MacOS
- Detect Data roaming in Android Application - Android
- WhatsApp Keyboard shortcuts for Mac - WhatsApp
- Command to know the installed Debian version? - Linux
- Error 50057 - User account is disabled. The account has been disabled by an administrator [Microsoft - Teams - Azure] - Microsoft
- How to insert date, time or custom timestamp in Notepad++ - NotepadPlusPlus
- How to minimize all Windows in Mac - MacOS