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==
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 show line numbers in Nano on Mac
- How to install Jupyter Notebook on macOS Sonoma
- How to Disable Remote Management using Mac Terminal
- Test internet speed using macOS Terminal command
- Docker Desktop needs privileged access macOS
- Google Search Hot Trends Screensaver for Mac OS X
- How to do calculations in Mac Terminal
- How to make TextEdit the default text Editor on Mac
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma)
- The Zsh Shell - Mac Tutorial
- Opening mac Terminal
- How to change the name of your Mac running on macOS Ventura 13
- How to find the Battery Cycle Count on macOS Ventura
- How to set an emoji as Zsh terminal prompt in macOS
- How to access Trash Folder using Mac Terminal Command
- macOS Ventura XCode Command Line Tools Installation
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13
- How to run .sh file in Mac Terminal
- Terminal Command to get the list of available shells in macOS
- How to see Storage Information on macOS Ventura
- How to Go To /usr/local/bin on Mac Terminal?
- How to do screen recording on Mac
- How to Find File and Directory Size in Mac Terminal
- Open .bash_profile File in TextEdit using Terminal
- Remove Now Playing icon from macOS Big Sur Menu Bar
More Posts:
- Android Development - How to switch between two Activities - Android
- Create simple struts2 project using maven commands - Java
- Increase or Decrease macOS Sonoma Sidebar Icon and Text Size - MacOS
- How to Measure Execution Time in Jupyter Notebook Cell - Python
- Python: Convert Minutes to Hours - Python
- Where are Plugins Installed in Notepad++ - NotepadPlusPlus
- [Android Studio] Error: Missing system image on device - Android-Studio
- How to hide toolbar on Notepad++ - NotepadPlusPlus