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 Terminal Base64 Command - Files](https://code2care.org/q/encode-decode-base64-string-using-mac-terminal-command/images/Terminal Base64 Command - Files.jpg)
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,
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
More Posts:
- Fix - Website Connection timed out Error Code 522 (Cloudflare) - HowTos
- How to check PowerShell version - Powershell
- WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. - PIP
- Program 14: Sum of Even Numbers from 1 to 100 - 1000+ Python Programs - Python-Programs
- Spring Boot CRUD Examples using JDBCTemplate - Java
- [Fix] Microsoft AADSTS900561: The endpoint only accepts POST requests. Received a GET request. - Microsoft
- Limit scrollback rows in macOS Terminal - MacOS
- How to know your iPhone Model Name - iOS