Skip to content

macOS commands

Terminal commands you actually need. Each one states whether it needs sudo, how risky it is, and how to undo it.

// In short

57 macOS terminal commands across 9 categories. Each is tagged with a danger level, a sudo flag, and — where it applies — a revert command, so a tweak can always be walked back. Homebrew paths are substituted for your CPU architecture.

Key facts
Interface
4
Audio and Bluetooth
3
Network
7
System and search
9
Hidden settings
11
Power and battery
5
Security
5
Disk
6
Homebrew
7
Your Mac
Homebrew in /opt/homebrew

// Interface

Restart menu bar and Control Center

Reloads the macOS menu bar. Use when clock, Wi-Fi, battery, or status menu icons freeze.

killall SystemUIServer
Related commandsRestart the Dock

Clear the font cache

sudocaution

Resets the system font cache. Fixes boxes, question marks, or garbled text in apps. Restart your Mac afterwards.

sudo atsutil databases -remove && atsutil server -shutdown

// Audio and Bluetooth

Reset the CoreAudio service

sudo

Restarts the audio daemon. Fixes an unresponsive volume control, missing sound, or crackling.

sudo killall coreaudiod

Restart the Bluetooth service

sudo

Reloads the Bluetooth stack. Helps when AirPods, wireless mice, or keyboards fail to connect.

sudo killall bluetoothd

Set the volume from Terminal

Sets output volume as a percentage (0–100). Handy in scripts or when volume keys stop working.

osascript -e "set volume output volume 50"

// Network

Flush the DNS cache

sudo

Resets the local DNS cache. Use when a site won't open, shows an old IP, or returns a DNS error.

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Restart the Wi-Fi interface

sudocaution

Reloads the en0 wireless module. The connection drops completely for a few seconds.

sudo ifconfig en0 down && sudo ifconfig en0 up
Related commandsRenew the DHCP lease

Show the local IP address

Prints the Mac's LAN IP (e.g. 192.168.1.42). Needed for SSH, file sharing, and dev servers.

ipconfig getifaddr en0

Show the public IP address

Prints the external IP the internet sees you from. Useful for checking VPNs and allowlists.

curl ifconfig.me

List processes listening on ports

sudo

Shows which processes await network connections. Finds "who took port 3000" and suspicious services.

sudo lsof -i -P -n | grep LISTEN

Reveal a saved Wi-Fi password

caution

Pulls the network password from the Keychain. Replace SSID with the network name; macOS asks for the admin password.

security find-generic-password -ga "SSID" -w

// Hidden settings

Show hidden files in Finder

Reveals hidden system files and folders (dot-prefixed) in Finder.

defaults write com.apple.finder AppleShowAllFiles YES && killall Finder
Revert
defaults write com.apple.finder AppleShowAllFiles NO && killall Finder

Hide system files in Finder

Restores default Finder behavior, hiding system files again.

defaults write com.apple.finder AppleShowAllFiles NO && killall Finder
Revert
defaults write com.apple.finder AppleShowAllFiles YES && killall Finder

Remove the Dock show delay

Makes an auto-hidden Dock appear instantly, without the default pause.

defaults write com.apple.dock autohide-delay -float 0 && killall Dock
Revert
defaults delete com.apple.dock autohide-delay && killall Dock

Dock with running apps only

Removes pinned items and shows only open apps — taskbar style.

defaults write com.apple.dock static-only -bool true && killall Dock
Revert
defaults write com.apple.dock static-only -bool false && killall Dock

Text selection in QuickLook

Lets you select and copy text right from the QuickLook preview window.

defaults write com.apple.finder QLEnableTextSelection -bool true && killall Finder
Revert
defaults write com.apple.finder QLEnableTextSelection -bool false && killall Finder

Window screenshots without shadow

Removes the pretty but bulky shadow around window screenshots (Cmd+Shift+4, then Space).

defaults write com.apple.screencapture disable-shadow -bool true && killall SystemUIServer
Revert
defaults write com.apple.screencapture disable-shadow -bool false && killall SystemUIServer

Screenshots as JPG instead of PNG

Saves disk space: JPG is much lighter than PNG. Supported: png, jpg, tiff, pdf, gif.

defaults write com.apple.screencapture type jpg && killall SystemUIServer
Revert
defaults write com.apple.screencapture type png && killall SystemUIServer

Custom folder for screenshots

Moves screenshots off the Desktop into a dedicated folder (create it first).

defaults write com.apple.screencapture location ~/Pictures/Screenshots && killall SystemUIServer
Revert
defaults delete com.apple.screencapture location && killall SystemUIServer

Always-expanded Save dialog

The "Save As" panel shows the folder picker right away, without an extra click.

defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
Revert
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool false

Path bar at the bottom of Finder windows

Shows the full path to the current folder at the window bottom — with quick level navigation.

defaults write com.apple.finder ShowPathbar -bool true && killall Finder
Revert
defaults write com.apple.finder ShowPathbar -bool false && killall Finder

No .DS_Store on network drives

Stops macOS from littering SMB shares and NAS volumes with .DS_Store files.

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
Revert
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool false

// Power and battery

Prevent sleep for a set time

Keeps the Mac awake for exactly 3600 seconds (1 hour), then restores normal behavior. Adjust the number as needed.

caffeinate -i -t 3600
Related commandsPrevent sleep

See what blocks sleep

Lists processes and assertions preventing sleep. The answer to "why won't it fall asleep".

pmset -g assertions
Related commandsPrevent sleep

Battery status from Terminal

Charge percentage, power source, and time remaining — faster than reaching for the menu.

pmset -g batt

All power management settings

Full dump of power settings: sleep timers, disk and display sleep, lid behavior.

pmset -g
Related commandsSee what blocks sleep

// Security

Gatekeeper status

Shows whether Gatekeeper app assessment is enabled.

spctl --status
Related commandsRemove app quarantine

Remove app quarantine

irreversible

Strips the Gatekeeper quarantine flag — fixes "app is damaged". Replace the path with yours.

Before you run this: You are manually switching off Apple's check for one app. Do it only for software downloaded from the developer's official site — on a file from an untrusted source this is a direct path to running malicious code.
xattr -d com.apple.quarantine /Applications/AppName.app
Related commandsGatekeeper status

FileVault encryption status

Shows whether full-disk encryption is on and if encryption is in progress.

fdesetup status

macOS firewall status

Shows whether the firewall blocking incoming connections is enabled.

/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

List SSH keys

Shows everything in ~/.ssh: id_ed25519/id_rsa key pairs, known_hosts, config.

ls -al ~/.ssh

// Disk

List all disks and partitions

Prints the hierarchy of disks, APFS volumes, and containers — required before any partition work.

diskutil list

Force-eject a disk

Ejects a volume Finder refuses to unmount ("disk in use"). Replace NAME with the volume name.

diskutil eject /Volumes/NAME

Empty the Trash from Terminal

irreversible

Permanently deletes Trash contents, including stuck files Finder can't remove.

Before you run this: Files are deleted with no confirmation and no way back — only a backup will bring them back. Check the Trash before running this.
rm -rf ~/.Trash/*

Clear Xcode DerivedData

irreversible

Frees tens of gigabytes: Xcode's intermediate builds and indexes. Projects survive — they rebuild on next launch.

Before you run this: Quit Xcode first. The next build of every project will be a full one, and completion indexes will be rebuilt from scratch.
rm -rf ~/Library/Developer/Xcode/DerivedData

Verify the system disk

sudo

Checks the file system for errors without making changes. May take several minutes.

sudo diskutil verifyVolume /

// Homebrew

Add Homebrew to your PATH

caution

The final install step people skip most often: without it the shell answers "brew: command not found". The path depends on the CPU — the command above is already set for the architecture you picked.

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile && eval "$(/opt/homebrew/bin/brew shellenv)"

List outdated packages

Shows formulae and apps with newer versions available, without installing anything.

brew outdated

Clean old versions and dependencies

Removes cached old package versions and unneeded dependencies. Frees noticeable disk space.

brew cleanup && brew autoremove

Homebrew diagnostics

Checks the brew installation for common issues: permissions, PATH, conflicts. The first command for any trouble.

brew doctor
Related commandsInstall Homebrew

List Homebrew-installed software

Shows formulae you installed explicitly (no dependencies) plus GUI apps from cask.

brew leaves && brew list --cask
Related commandsList outdated packages
// CONNECT

Contact Information

Submit a request or write to me directly on Telegram. I'll reply within 24 hours.