macOS Terminal commands

Terminal commands for the Mac settings Apple doesn’t put in System Settings: hidden files, Dock behaviour, screenshot options, keeping your Mac awake and checking battery health.

32 commands

Show hidden files in Finder

macOS

Reveals dotfiles and hidden folders everywhere in Finder. Tip: ⌘⇧. toggles this temporarily in any Finder window.

defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder

Hide hidden files again

macOS

Restores Finder’s default of hiding dotfiles.

defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder

Always show file extensions

macOS

Shows .pdf, .png, .app and every other extension in Finder.

defaults write NSGlobalDomain AppleShowAllExtensions -bool true && killall Finder

Show the path bar in Finder

macOS

Adds the folder path to the bottom of every Finder window.

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

Unhide your Library folder

macOS

Makes ~/Library visible in Finder permanently.

chflags nohidden ~/Library

Auto-hide the Dock instantly

macOS

Hides the Dock and removes the delay before it slides back in.

defaults write com.apple.dock autohide -bool true && defaults write com.apple.dock autohide-delay -float 0 && defaults write com.apple.dock autohide-time-modifier -float 0.4 && killall Dock

Restore the default Dock animation

macOS

Undoes the instant auto-hide tweak.

defaults delete com.apple.dock autohide-delay && defaults delete com.apple.dock autohide-time-modifier && killall Dock

Add a spacer to the Dock

macOS

Adds an empty gap you can drag between apps to group them.

defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' && killall Dock

Reset the Dock to factory layout

macOSCareful

Restores the original Dock apps and settings.

defaults delete com.apple.dock && killall Dock

Your custom Dock layout is lost.

Save screenshots to a folder

macOS

Stops screenshots cluttering your Desktop.

mkdir -p ~/ && defaults write com.apple.screencapture location ~/ && killall SystemUIServer

Change screenshot format

macOS

Use jpg, png, heic, pdf or tiff. Smaller JPGs are handy for sharing.

defaults write com.apple.screencapture type -string ""

Remove the shadow from window screenshots

macOS

Window captures (⌘⇧4 then Space) no longer include the drop shadow.

defaults write com.apple.screencapture disable-shadow -bool true

Keep your Mac awake

macOS

Prevents the display sleeping for the given number of seconds. Leave off -t to stay awake until you press Ctrl+C.

caffeinate -d -t

Flush the DNS cache

macOSAdmin

Fixes websites that won’t load after a DNS change.

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Battery charge and health

macOS

Shows the battery’s cycle count, condition and maximum capacity.

system_profiler SPPowerDataType | grep -E "Cycle Count|Condition|Maximum Capacity"

Hardware overview

macOS

Model, chip, memory and serial number.

system_profiler SPHardwareDataType

macOS version

macOS

Prints the product name, version and build.

sw_vers

Your local IP address

macOS

The Mac’s address on your Wi-Fi network (use en1 if en0 is empty).

ipconfig getifaddr en0

Strip formatting from the clipboard

macOS

Re-copies the clipboard as plain text, dropping fonts and colours. (ClepBoard also removes hidden characters.)

pbpaste | pbcopy

Copy a file’s contents to the clipboard

macOS

Puts the whole file on the clipboard without opening it.

pbcopy <

Open the current folder in Finder

macOS

Opens a Finder window for the folder your Terminal is in.

open .

Make your Mac talk

macOS

Speaks the text aloud. Chain it after long commands: npm run build; say done.

say ""

Toggle Dark Mode

macOS

Switches between Light and Dark appearance.

osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

Faster key repeat

macOS

Makes held keys repeat faster than System Settings allows. Log out and back in to apply.

defaults write NSGlobalDomain KeyRepeat -int 2 && defaults write NSGlobalDomain InitialKeyRepeat -int 15

Hold a key to repeat (no accent menu)

macOS

Holding a letter repeats it instead of showing accent options. Restart apps to apply.

defaults write -g ApplePressAndHoldEnabled -bool false

Stop .DS_Store files on network drives

macOS

Finder won’t litter shared and network folders with .DS_Store files.

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Open an app macOS says is "damaged"

macOSCareful

Removes the download quarantine flag from an app you trust.

xattr -dr com.apple.quarantine ""

Bypasses a Gatekeeper safety check. Only do this for apps from sources you trust.

Rebuild the Spotlight index

macOSAdmin

Fixes Spotlight not finding files. Re-indexing takes a while in the background.

sudo mdutil -E /

Fix sound that stopped working

macOSAdmin

Restarts the audio service; it relaunches automatically.

sudo killall coreaudiod

Free up inactive memory

macOSAdmin

Flushes disk caches from memory.

sudo purge

Sleep the display (lock)

macOS

Turns off the display immediately; locks if a password is required after sleep.

pmset displaysleepnow

Install developer command line tools

macOS

Installs git, make, clang and other tools developers need, without the full Xcode app.

xcode-select --install

Every command copies as plain, clean text: no curly quotes, no long dashes, no invisible characters.

Related guides