// CyberGrind · Orange Book · OS Infographic Series — 09 of 09

macOS Terminal Commands

zsh commands, macOS-specific BSD utilities, Homebrew, and key differences from Linux bash.

iTerm2 — zsh — macOS Sequoia
# macOS default shell is zsh (since Catalina). BSD tools differ from GNU (Linux) versions
logan@MacBook-Pro ~ % ls -lah ~/Documents | grep -i "\.pdf" | awk '{print $5, $9}'
1.2M Report_2024.pdf
macOS ≠ Linux: macOS uses BSD versions of core utilities. Key difference: sed -i '' requires empty string after -i on macOS (BSD), but not on Linux (GNU). This breaks Linux scripts on Mac. Install GNU coreutils via Homebrew for full compatibility.
// Navigation & macOS-Specific Commands
ls -lah -G
-G = colorized (BSD flag, not --color)
List files. BSD ls uses -G for color instead of GNU's --color=auto. -@ shows extended attributes.
open file.pdf | open -a Safari url
⚠ macOS ONLY — opens in Finder/app
Opens file with default application — like double-clicking in Finder. open . opens current folder in Finder.
pbcopy < file.txt | pbpaste
⚠ macOS ONLY — clipboard
pbcopy writes stdin to clipboard. pbpaste reads clipboard to stdout. cat file | pbcopy copies file content.
mdfind "kMDItemKind == 'PDF'"
⚠ macOS ONLY — Spotlight CLI
Uses Spotlight metadata index — much faster than find for content searches. -onlyin to scope to directory.
sed -i '' 's/old/new/g' file.txt
⚠ BSD sed REQUIRES '' after -i
Critical difference: BSD sed needs empty string after -i. Linux GNU sed does not. Breaks cross-platform scripts!
lsof -iTCP -sTCP:LISTEN -n -P
macOS uses lsof — Linux uses ss
List listening ports. macOS uses lsof for this; Linux uses ss. -n=no DNS -P=no port names.
sw_vers | diskutil list
system info · disk utility
sw_vers shows macOS version/build. diskutil list shows all disks. diskutil info /dev/disk0 for details.
defaults write com.apple.Finder AppleShowAllFiles YES
macOS preferences DB
Read/write macOS app preferences stored in plist files. Show hidden files, change Dock behavior, etc.
// Homebrew — macOS Package Manager
brew install nmap
Install a CLI package (formula)
brew install --cask firefox
Install a GUI app (cask)
brew upgrade
Upgrade all installed packages
brew list | brew search term
List installed / search packages
brew uninstall package
Remove a package
brew doctor
Diagnose Homebrew issues
// macOS BSD vs Linux GNU — Key Differences
TaskmacOS (BSD)Linux (GNU)
In-place sedsed -i '' 's/x/y/g' filesed -i 's/x/y/g' file
Colorized lsls -Gls --color=auto
Listening portslsof -iTCP -sTCP:LISTENss -tlnp
Network interfacesifconfig / networksetupip addr show
Service managementlaunchctl (launchd)systemctl (systemd)
File metadata searchmdfind (Spotlight)locate / find
Open in GUIopen file.pdfxdg-open file.pdf
Clipboardpbcopy / pbpastexclip / xsel
System versionsw_versuname -a / lsb_release
RAM infosysctl -n hw.memsizefree -h
Install packagesbrew install packageapt / dnf / pacman
Default shellzsh (Catalina+)bash (most distros)
// Keyboard Shortcuts
Ctrl + CInterrupt / kill running command
Ctrl + RReverse search command history
Ctrl + A/EJump to start / end of line
Ctrl + LClear screen (same as clear)
Ctrl + ZSuspend to background (fg resume)
TabAutocomplete (zsh: Tab twice = menu)