Skip to content

macOS CLI Cheat Sheet

macOS-specific commands and tools.

CommandDescription
open .Open current dir in Finder
open file.pdfOpen file with default app
open -a "App Name" fileOpen with specific app
open -R fileReveal in Finder
open -e fileOpen in TextEdit
open https://...Open URL in browser
qlmanage -p fileQuick Look preview
CommandDescription
pbcopy < fileCopy file contents to clipboard
pbpaste > filePaste clipboard to file
echo "text" | pbcopyCopy text to clipboard
pbpaste | grep patternProcess clipboard contents
pbpaste | wc -lCount lines in clipboard
CommandDescription
mdfind "query"Spotlight search
mdfind -name "filename"Search by filename
mdfind -onlyin ~/Documents "query"Search in directory
mdfind "kMDItemKind == 'PDF'"Search by file type
mdfind "date:today"Files modified today
mdls fileShow file metadata
mdutil -s /Spotlight indexing status
CommandDescription
sw_versmacOS version info
system_profilerFull system info
system_profiler SPHardwareDataTypeHardware info
uname -aKernel info
sysctl -n machdep.cpu.brand_stringCPU model
sysctl hw.memsizeTotal RAM
hostnameComputer name
scutil --get ComputerNameFriendly computer name
CommandDescription
caffeinatePrevent sleep (Ctrl+C to stop)
caffeinate -t 3600Prevent sleep for 1 hour
caffeinate -sPrevent sleep while on AC
caffeinate -dPrevent display sleep
pmset -gPower management settings
pmset sleepnowSleep immediately
shutdown -h nowShutdown
shutdown -r nowRestart
CommandDescription
say "Hello world"Text to speech
say -v "?"List available voices
say -v Samantha "Hello"Specific voice
say -o audio.aiff "text"Save to file
afplay audio.mp3Play audio file
osascript -e 'set volume 5'Set volume (0-7)
osascript -e 'set volume output muted true'Mute
CommandDescription
diskutil listList all disks
diskutil info disk0Disk info
diskutil mount disk2s1Mount volume
diskutil unmount /Volumes/NameUnmount volume
diskutil eject disk2Eject disk
diskutil eraseDisk APFS "Name" disk2Erase and format
hdiutil create -size 1g -fs APFS -volname "Vol" disk.dmgCreate DMG
hdiutil attach disk.dmgMount DMG
hdiutil detach /Volumes/VolUnmount DMG
CommandDescription
whoamiCurrent user
idUser ID and groups
dscl . -list /UsersList all users
dscl . -read /Users/usernameUser details
dscacheutil -q user -a name usernameQuery user info
dscacheutil -flushcacheFlush DNS cache
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderFull DNS flush
CommandDescription
launchctl listList loaded services
launchctl list | grep nameFind service
launchctl load ~/Library/LaunchAgents/com.example.plistLoad service
launchctl unload ~/Library/LaunchAgents/com.example.plistUnload service
launchctl start com.example.serviceStart service
launchctl stop com.example.serviceStop service
PathScope
~/Library/LaunchAgentsCurrent user
/Library/LaunchAgentsAll users
/Library/LaunchDaemonsSystem (root)
/System/Library/LaunchDaemonsApple system
CommandDescription
defaults readAll preferences
defaults read com.apple.finderApp preferences
defaults read com.apple.dock autohideSpecific key
defaults write com.apple.dock autohide -bool trueSet boolean
defaults write com.apple.dock autohide-delay -float 0Set float
defaults delete com.apple.dock autohideRemove key
killall DockRestart Dock (apply changes)
killall FinderRestart Finder
Terminal window
# Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder
# Show path bar in Finder
defaults write com.apple.finder ShowPathbar -bool true
# Disable press-and-hold for keys (enable key repeat)
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# Set fast key repeat
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Screenshot location
defaults write com.apple.screencapture location ~/Screenshots
killall SystemUIServer
# Screenshot format (png, jpg, pdf)
defaults write com.apple.screencapture type png
CommandDescription
brew install packageInstall package
brew install --cask appInstall GUI app
brew uninstall packageRemove package
brew listList installed
brew list --caskList installed apps
brew search nameSearch packages
brew info packagePackage info
brew updateUpdate Homebrew
brew upgradeUpgrade all packages
brew upgrade packageUpgrade specific
brew outdatedList outdated
brew cleanupRemove old versions
brew doctorDiagnose issues
brew services listList services
brew services start nameStart service
brew services stop nameStop service
brew services restart nameRestart service
CommandDescription
softwareupdate -lList available updates
softwareupdate -i -aInstall all updates
softwareupdate -i "update-name"Install specific update
softwareupdate --install-rosettaInstall Rosetta 2 (Apple Silicon)
CommandDescription
networksetup -listallhardwareportsList network interfaces
networksetup -getairportnetwork en0Current WiFi network
networksetup -setairportpower en0 offTurn off WiFi
networksetup -setairportpower en0 onTurn on WiFi
airport -sScan for WiFi networks
ifconfig en0Interface info
ipconfig getifaddr en0Local IP address
networkQualityInternet speed test (macOS 12+)
CommandDescription
security find-generic-password -a "account" -s "service" -wGet password from Keychain
security add-generic-password -a "account" -s "service" -w "password"Add to Keychain
spctl --statusGatekeeper status
spctl --master-disableDisable Gatekeeper
xattr -l fileList extended attributes
xattr -d com.apple.quarantine fileRemove quarantine flag
xattr -cr /Applications/App.appClear all xattrs (fix “damaged” apps)
codesign -v /Applications/App.appVerify code signature
CommandDescription
xattr -l fileList extended attributes
xattr -c fileClear all attributes
GetFileInfo fileClassic file info
SetFile -a V fileMake invisible
chflags hidden fileHide file
chflags nohidden fileUnhide file
CommandDescription
screencapture -i screenshot.pngInteractive capture
screencapture -cCapture to clipboard
screencapture -T 5 screenshot.pngDelay 5 seconds
screencapture -w screenshot.pngCapture window
screencapture -x screenshot.pngNo sound
ShortcutAction
Cmd+Shift+3Full screen screenshot
Cmd+Shift+4Selection screenshot
Cmd+Shift+4+SpaceWindow screenshot
Cmd+Shift+5Screenshot toolbar
CommandDescription
mdfind "kMDItemKind == 'Application'"List all apps
system_profiler SPApplicationsDataTypeDetailed app list
lsappinfo listRunning apps info
osascript -e 'quit app "App Name"'Quit app
osascript -e 'tell app "Finder" to restart'Restart Finder
killall "App Name"Force quit app
Terminal window
# Display notification
osascript -e 'display notification "Body" with title "Title"'
# Display dialog
osascript -e 'display dialog "Message" buttons {"OK"}'
# Get frontmost app
osascript -e 'tell application "System Events" to get name of first process whose frontmost is true'
# Set volume
osascript -e 'set volume output volume 50'
# Get clipboard
osascript -e 'the clipboard'
# Empty trash
osascript -e 'tell application "Finder" to empty trash'
Terminal window
# Watch file changes
fswatch -o . | xargs -n1 -I{} echo "Changed"
# Copy file path to clipboard
pwd | pbcopy
# Open man page in Preview as PDF
man -t ls | open -f -a Preview
# Get bundle ID of app
osascript -e 'id of app "Safari"'
# Set default app for file type (requires duti)
duti -s com.apple.Safari .html all
# Quick timer
caffeinate -t 1800 && say "Timer done"
# Flush DNS
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder
# Show/hide desktop icons
defaults write com.apple.finder CreateDesktop false && killall Finder
defaults write com.apple.finder CreateDesktop true && killall Finder
# Reset Launchpad
defaults write com.apple.dock ResetLaunchPad -bool true && killall Dock
# Prevent .DS_Store on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
  • Shell — Scripting patterns, loops, conditionals, functions
  • Unix — Shell commands, file ops, text processing
  • Terminal Emulators — iTerm2 vs Ghostty, rendering, decision guide
  • CLI-First — Why terminal-first workflows