Master macOS Terminal: Essential Commands for Beginners and Power Users
This guide introduces macOS Terminal, explains what a terminal is, shows how to open it, covers fundamental commands such as navigation, file handling, system settings, and advanced utilities like diskutil and Homebrew, while warning about risky operations and offering practical examples.
What is the Terminal?
The terminal is a bridge between the operating system kernel and the user interface, allowing users to type commands that the system executes directly.
How to Open the Terminal
You can launch the Terminal app from the Applications folder or by using the system-wide search (Spotlight) and typing "Terminal" or "终端" then pressing Enter.
Basic Concepts
When the terminal starts, it waits for a command. A command consists of an object (e.g., say), optional modifiers (e.g., -r 500), and arguments (e.g., hi).
Examples: say hi – makes the computer speak the word "hi". echo "Your text" – prints the supplied text back to the console.
File System Navigation
Use pwd to display the current working directory. Paths can be absolute (starting with /) or relative (starting with .).
Change directories with cd: cd /Applications – go to the Applications folder (absolute path). cd ./Utilities – move into the Utilities subfolder from the current location (relative path).
List directory contents with ls. Add -R to list recursively.
Clear the screen with clear.
Administrative Commands
Commands that can modify system files require sudo to gain super‑user privileges.
Example of a dangerous command (do NOT run):
sudo diskutil eraseVolume free none diskxSystem Preferences via defaults
The defaults utility edits macOS property list (plist) files that store default settings for applications. Common examples: defaults write com.apple.CrashReporter DialogType none – disables crash report dialogs. defaults write com.apple.screencapture type jpg – changes default screenshot format to JPEG.
defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder– shows hidden files in Finder.
Disk Management with diskutil
Use diskutil list to view current disk layout. For APFS volumes use diskutil apfs, for HFS/HFS+ use diskutil, and for CoreStorage use diskutil cs. Risky operations (e.g., resizing, unmounting) are listed but should be executed only with full understanding.
Package Management with Homebrew
Homebrew is a third‑party package manager for macOS. Install it with:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"After installation, you can install software via brew install <package> or brew cask install <app>.
File Operations
Common file commands include: cp – copy files. mv – move or rename files. mkdir – create directories. cat – display file contents.
Conversion with textutil
textutilconverts documents between formats such as txt, html, rtf, doc, docx, odt, etc. Example:
textutil -convert txt /path/to/file.docxSafety Warnings
Commands like rm -rf can irreversibly delete files, especially when combined with sudo. Always verify the command and its target path before execution.
Running destructive commands inside a virtual machine without proper sandboxing can still affect the host system, as demonstrated by an experiment that accidentally erased over 100 GB of data on the author’s Mac.
Conclusion
The terminal offers powerful control over macOS. Beginners can start with simple, harmless commands to automate routine tasks, while advanced users can customize system behavior through defaults, diskutil, and Homebrew. However, always treat the terminal with respect and double‑check commands to avoid irreversible damage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
