This guide covers tools that only exist on macOS. Everyday commands such as ls, grep and ssh work on a Mac too, and they're in the Linux guide. Commands that start with sudo ask for your password. Names such as en0, Wi-Fi and disk2 are examples, so check yours with networksetup -listallhardwareports or diskutil list.
System information #
-
Show the macOS version and buildmacOS
sw_vers -
Show just the macOS version numbermacOS
sw_vers -productVersion -
Show the Mac model, chip, memory and serial numbermacOS
system_profiler SPHardwareDataType -
Show the processor namemacOS
sysctl -n machdep.cpu.brand_string -
Check whether the Mac is Apple silicon or IntelmacOS
uname -m -
Show how long the Mac has been runningmacOS
uptime -
Show the Mac's namemacOS
scutil --get ComputerName -
Change the Mac's namemacOS
sudo scutil --set ComputerName "Gerard's Mac" -
Change the Mac's local network namemacOS
sudo scutil --set LocalHostName gerards-mac -
Install the Xcode command line toolsmacOS
xcode-select --install -
Install Rosetta for Intel apps on Apple siliconmacOS
softwareupdate --install-rosetta --agree-to-license
Homebrew #
-
Install HomebrewmacOS
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Search for a packagemacOS
brew search wget -
Show a package's detailsmacOS
brew info wget -
Install a command-line toolmacOS
brew install wget -
Install an appmacOS
brew install --cask visual-studio-code -
List installed packagesmacOS
brew list -
See which packages have updatesmacOS
brew outdated -
Update Homebrew's package listmacOS
brew update -
Upgrade all packagesmacOS
brew upgrade -
Upgrade one packagemacOS
brew upgrade wget -
Upgrade apps, including ones that update themselvesmacOS
brew upgrade --cask --greedy -
Stop a package from being upgradedmacOS
brew pin node -
Show which installed packages depend on a packagemacOS
brew uses --installed wget -
Uninstall a packagemacOS
brew uninstall wget -
Remove old versions and cached downloadsmacOS
brew cleanup -
Check Homebrew for problemsmacOS
brew doctor -
Save a list of your packages to a BrewfilemacOS
brew bundle dump -
Install everything in a BrewfilemacOS
brew bundle -
List background services installed with HomebrewmacOS
brew services list -
Start a Homebrew service and run it at loginmacOS
brew services start postgresql@16 -
Stop a Homebrew servicemacOS
brew services stop postgresql@16
Software updates #
-
List available macOS updatesmacOS
softwareupdate --list -
Install all macOS updatesmacOS
sudo softwareupdate --install --all -
Install all macOS updates and restartmacOS
sudo softwareupdate --install --all --restart -
List full macOS installers you can downloadmacOS
softwareupdate --list-full-installers -
Download a full macOS installermacOS
softwareupdate --fetch-full-installer --full-installer-version 15.1 -
Install the Mac App Store command-line toolmacOS
brew install mas -
List apps installed from the App StoremacOS
mas list -
Update App Store appsmacOS
mas upgrade
Finder and files #
-
Open a file with its default appmacOS
open report.pdf -
Open the current folder in FindermacOS
open . -
Open a folder in a specific appmacOS
open -a "Visual Studio Code" . -
Show a file in FindermacOS
open -R report.pdf -
Open a web page in your default browsermacOS
open https://commandguide.com -
Preview a file with Quick LookmacOS
qlmanage -p photo.png -
Copy a folder, keeping all Mac metadatamacOS
ditto source/ backup/ -
Zip a folder the same way Finder doesmacOS
ditto -c -k --keepParent folder folder.zip -
Create a compressed disk image from a foldermacOS
hdiutil create -volname Projects -srcfolder ~/Projects -ov -format UDZO projects.dmg -
Open a disk imagemacOS
hdiutil attach app.dmg -
Eject a disk imagemacOS
hdiutil detach /Volumes/App -
Hide a file in FindermacOS
chflags hidden file.txt -
Unhide a file in FindermacOS
chflags nohidden file.txt -
Lock a file so it can't be changedmacOS
chflags uchg file.txt -
Unlock a filemacOS
chflags nouchg file.txt -
Show a file's extended attributesmacOS
xattr -l app.dmg -
Convert a HEIC photo to JPEGmacOS
sips -s format jpeg photo.heic --out photo.jpg -
Resize an image so its longest side is 1200 pixelsmacOS
sips -Z 1200 photo.jpgWarning: Changes the image straight away, with no backup.
-
Convert a Word document to plain textmacOS
textutil -convert txt report.docx -
Print a filemacOS
lpr report.pdf
Clipboard, screenshots and speech #
-
Copy a command's output to the clipboardmacOS
ls | pbcopy -
Copy a file's contents to the clipboardmacOS
pbcopy < notes.txt -
Paste the clipboardmacOS
pbpaste -
Save the clipboard to a filemacOS
pbpaste > notes.txt -
Take a screenshot of the whole screenmacOS
screencapture screen.png -
Take a screenshot of an area or window you choosemacOS
screencapture -i shot.png -
Take a screenshot after 5 secondsmacOS
screencapture -T 5 screen.png -
Take a screenshot and copy it to the clipboardmacOS
screencapture -c -
Record the screenmacOS
screencapture -v recording.mov -
Change where screenshots are savedmacOS
defaults write com.apple.screencapture location ~/Pictures/Screenshots && killall SystemUIServer -
Save screenshots as JPEGmacOS
defaults write com.apple.screencapture type jpg && killall SystemUIServer -
Remove the shadow from window screenshotsmacOS
defaults write com.apple.screencapture disable-shadow -bool true && killall SystemUIServer -
Speak some textmacOS
say "Build finished" -
Save spoken text to an audio filemacOS
say -o hello.aiff "Hello" -
Show a notificationmacOS
osascript -e 'display notification "Build finished" with title "Terminal"'
Spotlight #
-
Search for files with SpotlightmacOS
mdfind "invoice" -
Find files by namemacOS
mdfind -name report.pdf -
Search inside one foldermacOS
mdfind -onlyin ~/Documents "invoice" -
Find files larger than 1 GBmacOS
mdfind "kMDItemFSSize > 1000000000" -
List every app on the MacmacOS
mdfind "kMDItemContentType == 'com.apple.application-bundle'" -
Show a file's Spotlight metadata, including where it was downloaded frommacOS
mdls report.pdf -
Check whether Spotlight is indexing a drivemacOS
mdutil -s / -
Rebuild the Spotlight indexmacOS
sudo mdutil -E / -
Stop Spotlight indexing a drivemacOS
sudo mdutil -i off /Volumes/Backup
Settings with defaults #
-
Show all of an app's settingsmacOS
defaults read com.apple.dock -
Show one settingmacOS
defaults read com.apple.dock autohide -
Search all settings for a wordmacOS
defaults find autohide -
List the apps that have settingsmacOS
defaults domains -
Reset one setting to its defaultmacOS
defaults delete com.apple.dock autohide -
Back up an app's settings to a filemacOS
defaults export com.apple.dock dock.plist -
Restore an app's settings from a filemacOS
defaults import com.apple.dock dock.plist -
Show a settings (plist) file in readable formmacOS
plutil -p ~/Library/Preferences/com.apple.dock.plist -
Check a plist file for errorsmacOS
plutil -lint settings.plist -
Convert a plist file to XMLmacOS
plutil -convert xml1 settings.plist -
Show hidden files in FindermacOS
defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder -
Hide hidden files in Finder againmacOS
defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder -
Show the path bar in FindermacOS
defaults write com.apple.finder ShowPathbar -bool true && killall Finder -
Show all file extensionsmacOS
defaults write NSGlobalDomain AppleShowAllExtensions -bool true && killall Finder -
Stop Finder making .DS_Store files on network drivesmacOS
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true -
Save new documents to the Mac instead of iCloudmacOS
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false -
Open save dialogs fully expandedmacOS
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true -
Make keys repeat faster (sign out to apply)macOS
defaults write NSGlobalDomain KeyRepeat -int 2 -
Repeat keys when held instead of showing accentsmacOS
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
Dock #
-
Hide the Dock automaticallymacOS
defaults write com.apple.dock autohide -bool true && killall Dock -
Show a hidden Dock instantlymacOS
defaults write com.apple.dock autohide-delay -float 0 && killall Dock -
Change the Dock's icon sizemacOS
defaults write com.apple.dock tilesize -int 48 && killall Dock -
Stop showing recent apps in the DockmacOS
defaults write com.apple.dock show-recents -bool false && killall Dock -
Add a gap between Dock appsmacOS
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' && killall Dock -
Reset the DockmacOS
defaults delete com.apple.dock && killall DockWarning: Removes every app you've added to the Dock and all Dock settings.
Apps and processes #
-
Open an appmacOS
open -a Safari -
Open another copy of an appmacOS
open -na "Google Chrome" -
Quit an app normallymacOS
osascript -e 'quit app "Safari"' -
Force an app to quitmacOS
killall SafariWarning: The app can't save, so unsaved work may be lost.
-
Show an app's bundle IDmacOS
osascript -e 'id of app "Safari"' -
Show processes by CPU usemacOS
top -o cpu -
Restart FindermacOS
killall Finder -
Restart the DockmacOS
killall Dock -
Restart the menu barmacOS
killall SystemUIServer -
Keep the Mac awake while a command runsmacOS
caffeinate -i make build -
Keep the Mac awake for an hourmacOS
caffeinate -t 3600 -
Keep the display on until you press Ctrl+CmacOS
caffeinate -d
launchd and background jobs #
-
List your background jobsmacOS
launchctl list -
Find a background job by namemacOS
launchctl list | grep docker -
Show a background job's detailsmacOS
launchctl print gui/$(id -u)/com.example.backup -
Load a launch agentmacOS
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.backup.plist -
Unload a launch agentmacOS
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.example.backup.plist -
Restart a background jobmacOS
launchctl kickstart -k gui/$(id -u)/com.example.backup -
Restart a system servicemacOS
sudo launchctl kickstart -k system/com.openssh.sshd -
Stop a background job starting automaticallymacOS
launchctl disable gui/$(id -u)/com.example.backup -
Let a disabled background job start againmacOS
launchctl enable gui/$(id -u)/com.example.backup -
List login items and background itemsmacOS
sudo sfltool dumpbtm
Logs and diagnostics #
-
Watch the system log for one processmacOS
log stream --predicate 'process == "sshd"' -
Search the last hour of logs for errorsmacOS
log show --last 1h --predicate 'eventMessage CONTAINS "error"' -
Save the last hour of logs to a filemacOS
sudo log collect --last 1h -
Open the folder of crash reportsmacOS
open ~/Library/Logs/DiagnosticReports -
Collect a full diagnostics report for ApplemacOS
sudo sysdiagnose
Network #
-
List network services, such as Wi-Fi and EthernetmacOS
networksetup -listallnetworkservices -
List network ports and their device namesmacOS
networksetup -listallhardwareports -
Show a network service's IP settingsmacOS
networksetup -getinfo Wi-Fi -
Show the IP address of an interfacemacOS
ipconfig getifaddr en0 -
Show an interface's MAC addressmacOS
ifconfig en0 ether -
Show the default gatewaymacOS
route -n get default -
Show the DNS servers in usemacOS
scutil --dns -
Show a network service's DNS serversmacOS
networksetup -getdnsservers Wi-Fi -
Set a network service's DNS serversmacOS
sudo networksetup -setdnsservers Wi-Fi 1.1.1.1 8.8.8.8 -
Go back to the DNS servers from DHCPmacOS
sudo networksetup -setdnsservers Wi-Fi empty -
Clear the DNS cachemacOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder -
Set a static IP addressmacOS
sudo networksetup -setmanual Ethernet 192.168.1.50 255.255.255.0 192.168.1.1 -
Switch a network service to DHCPmacOS
sudo networksetup -setdhcp Ethernet -
Renew the DHCP leasemacOS
sudo ipconfig set en0 DHCP -
Show the order network services are used inmacOS
networksetup -listnetworkserviceorder -
Show proxy settingsmacOS
scutil --proxy -
Test your internet speed and responsivenessmacOS
networkQuality -
List listening portsmacOS
sudo lsof -iTCP -sTCP:LISTEN -n -P -
Find what's using a portmacOS
lsof -i :8080 -
Turn on Remote Login (SSH)macOS
sudo systemsetup -setremotelogin on
Wi-Fi #
-
Turn Wi-Fi offmacOS
networksetup -setairportpower en0 off -
Turn Wi-Fi onmacOS
networksetup -setairportpower en0 on -
Join a Wi-Fi networkmacOS
networksetup -setairportnetwork en0 HomeWiFiWarning: Your Wi-Fi password is saved in your shell history.
-
Show Wi-Fi details, including nearby networksmacOS
system_profiler SPAirPortDataType -
Show detailed Wi-Fi diagnosticsmacOS
sudo wdutil info -
Show a saved Wi-Fi network's passwordmacOS
security find-generic-password -wa "HomeWiFi"
Firewall #
-
Check whether the firewall is onmacOS
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate -
Turn the firewall onmacOS
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on -
Turn the firewall offmacOS
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate offWarning: Leaves the Mac unprotected. Turn it back on when you're done.
-
Turn on stealth modemacOS
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on -
List apps and whether they're allowedmacOS
/usr/libexec/ApplicationFirewall/socketfilterfw --listapps -
Allow an app through the firewallmacOS
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/MyApp.app -
Block an app's incoming connectionsmacOS
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /Applications/MyApp.app -
Show the packet filter (pf) statusmacOS
sudo pfctl -s info
Disks #
-
List disks and volumesmacOS
diskutil list -
Show a disk's detailsmacOS
diskutil info disk2 -
Check a disk's SMART statusmacOS
diskutil info disk0 | grep SMART -
List APFS containers and volumesmacOS
diskutil apfs list -
Check a volume for errorsmacOS
diskutil verifyVolume / -
Repair a volumemacOS
sudo diskutil repairVolume /Volumes/Backup -
Mount a volumemacOS
diskutil mount disk2s1 -
Unmount a volumemacOS
diskutil unmount /Volumes/Backup -
Eject a diskmacOS
diskutil eject disk2 -
Rename a volumemacOS
diskutil rename /Volumes/Untitled Backup -
Add an APFS volume to a containermacOS
diskutil apfs addVolume disk3 APFS Projects -
Erase a disk as APFSmacOS
diskutil eraseDisk APFS Backup disk2Warning: Erases everything on the disk. Check the disk name with diskutil list first.
-
Erase a disk as exFAT for Mac and WindowsmacOS
diskutil eraseDisk ExFAT USB GPT disk2Warning: Erases everything on the disk. Check the disk name with diskutil list first.
-
Make a bootable macOS installer on a USB drivemacOS
sudo /Applications/Install\ macOS\ Sequoia.app/Contents/Resources/createinstallmedia --volume /Volumes/USBWarning: Erases everything on the USB drive.
Time Machine #
-
Show Time Machine's statusmacOS
tmutil status -
Start a backup nowmacOS
tmutil startbackup -
Show the backup drive's detailsmacOS
tmutil destinationinfo -
Show the latest backupmacOS
tmutil latestbackup -
List all backupsmacOS
tmutil listbackups -
Leave a folder out of backupsmacOS
tmutil addexclusion ~/Downloads -
Check whether a folder is left out of backupsmacOS
tmutil isexcluded ~/Downloads -
List local snapshotsmacOS
tmutil listlocalsnapshots /
Power and sleep #
-
Show power settingsmacOS
pmset -g -
Show battery chargemacOS
pmset -g batt -
Show battery health and cycle countmacOS
system_profiler SPPowerDataType -
Show what's stopping the Mac from sleepingmacOS
pmset -g assertions -
Show recent sleep and wake timesmacOS
pmset -g log | grep -E "Sleep|Wake" -
Put the Mac to sleepmacOS
pmset sleepnow -
Turn the display offmacOS
pmset displaysleepnow -
Turn the display off after 10 minutes on the chargermacOS
sudo pmset -c displaysleep 10 -
Never sleep on the chargermacOS
sudo pmset -c sleep 0 -
Turn on Low Power ModemacOS
sudo pmset -a lowpowermode 1 -
Wake or start the Mac at 7am on weekdaysmacOS
sudo pmset repeat wakeorpoweron MTWRF 07:00:00 -
Cancel scheduled wake and start timesmacOS
sudo pmset repeat cancel -
Restart nowmacOS
sudo shutdown -r now -
Shut down nowmacOS
sudo shutdown -h now -
Shut down in 30 minutesmacOS
sudo shutdown -h +30 -
Sign outmacOS
osascript -e 'tell application "System Events" to log out'
Security and Gatekeeper #
-
Check whether Gatekeeper is onmacOS
spctl --status -
Check whether Gatekeeper will let an app openmacOS
spctl --assess --verbose /Applications/MyApp.app -
Show who signed an appmacOS
codesign -dv --verbose=4 /Applications/MyApp.app -
Check an app's signature is intactmacOS
codesign --verify --deep --strict /Applications/MyApp.app -
Remove the downloaded-from-internet flag from an appmacOS
xattr -d com.apple.quarantine /Applications/MyApp.appWarning: Skips Gatekeeper's check. Only do it for apps you trust.
-
Check whether System Integrity Protection is onmacOS
csrutil status -
Check whether FileVault is onmacOS
fdesetup status -
Turn on FileVaultmacOS
sudo fdesetup enable -
Reset an app's privacy permissionsmacOS
tccutil reset All com.example.app -
List code-signing certificatesmacOS
security find-identity -v -p codesigning
Keychain #
-
Save a password in the keychain (asks for it)macOS
security add-generic-password -a "$USER" -s "MyService" -w -
Show a saved passwordmacOS
security find-generic-password -s "MyService" -w -
Delete a saved passwordmacOS
security delete-generic-password -s "MyService" -
List keychainsmacOS
security list-keychains -
Lock the login keychainmacOS
security lock-keychain ~/Library/Keychains/login.keychain-db
Users and groups #
-
List user accountsmacOS
dscl . list /Users | grep -v '^_' -
Show your account's detailsmacOS
dscl . read /Users/$USER -
List the groups you're inmacOS
id -Gn -
List administratorsmacOS
dscl . read /Groups/admin GroupMembership -
Create a user (asks for the password)macOS
sudo sysadminctl -addUser alice -fullName "Alice Smith" -password - -
Make a user an administratormacOS
sudo dseditgroup -o edit -a alice -t user admin -
Remove a user's administrator rightsmacOS
sudo dseditgroup -o edit -d alice -t user admin -
Change your passwordmacOS
passwd -
Check whether the guest account is onmacOS
sudo sysadminctl -guestAccount status -
Delete a user and their home foldermacOS
sudo sysadminctl -deleteUser aliceWarning: Deletes the user's files and can't be undone.
Automation #
-
Run an AppleScript commandmacOS
osascript -e 'tell application "Music" to play' -
List your ShortcutsmacOS
shortcuts list -
Run a ShortcutmacOS
shortcuts run "Resize Image" -
Set the volume to 50%macOS
osascript -e 'set volume output volume 50' -
Mute the soundmacOS
osascript -e 'set volume output muted true' -
Switch between light and dark modemacOS
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode' -
Empty the TrashmacOS
osascript -e 'tell application "Finder" to empty trash'Warning: Deletes everything in the Trash and can't be undone.