This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

macOS CLI Utilities Cheatsheet

A quick reference guide for macOS Darwin terminal commands: launchctl daemons, Finder and Dock defaults, DNS flushing, Spotlight indexing, pbcopy, and sips.

· Published

macOS includes a wealth of Darwin UNIX commands and system administration utilities for controlling GUI subsystems, daemons, and system services directly from the Terminal.

System Services & Daemon Paths

~/Library/LaunchAgents         # Per-user agents provided by the user
/Library/LaunchAgents/         # Per-user agents provided by administrator
/Library/LaunchDaemons/        # System-wide daemons provided by administrator
/System/Library/LaunchAgents/  # macOS native per-user agents
/System/Library/LaunchDaemons/ # macOS native system daemons

List active services:

launchctl list

Finder & Dock Tweaks

# Hide / Show all desktop icons
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
defaults write com.apple.finder CreateDesktop -bool true && killall Finder

# Single-app mode for Dock (clicking an app hides all other windows)
defaults write com.apple.dock single-app -bool true && killall Dock
defaults delete com.apple.dock single-app && killall Dock

# Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder

Networking & DNS Cache

# Flush DNS resolver cache
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Configure SOCKS proxy via CLI
sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 1080
sudo networksetup -setsocksfirewallproxystate Wi-Fi on
sudo networksetup -setsocksfirewallproxystate Wi-Fi off

Spotlight Indexing (mdutil)

# Disable Spotlight indexing across all volumes
sudo mdutil -a -i off

# Disable indexing for a specific drive mount point
sudo mdutil -i off /Volumes/ExternalDrive

# Exclude a directory from Spotlight indexing
touch /path/to/folder/.metadata_never_index

Essential macOS Command-Line Utilities

Tool Purpose Example
open Opens files, URLs, or apps as if double-clicked open -a "Google Chrome" https://example.com
pbcopy Copies standard input to system clipboard cat id_rsa.pub | pbcopy
pbpaste Prints system clipboard contents to stdout pbpaste > output.txt
sips Scriptable image processing system sips -Z 640 image.jpg
screencapture Capture screenshots from CLI screencapture -i screenshot.png
textutil Batch converts text formats (HTML, docx, rtf) textutil -convert html document.rtf
tmutil Controls Time Machine backups tmutil startbackup
mdfind Searches files using Spotlight database mdfind "kMDItemKind == 'PDF'"

References

Related topics