tips
60 tips Mac terminal
One command, setting or habit at a time about Mac terminal: what it does, the line to copy and a caveat or two.
Mac terminal 60
-
Prints the battery cycle count of a MacBook straight from the terminal.
ioreg -rn AppleSmartBattery | grep CycleCount -
Save a set of Terminal windows and tabs under a name and reopen them in one click.
-
Copy your Terminal colours, fonts and shell settings to another Mac with an exported profile file.
-
Grab an exact rectangle of the screen with identical size each run.
screencapture -R 0,0,1280,720 ~/Desktop/step-1.png -
Test your own command line program for leaked allocations.
leaks -atExit -- ./myprogram --some-option -
Explains why the terminal stops responding after Ctrl-S and how to stop that for good.
stty -ixon -
See every installed system extension, such as VPN or security agents, and its state.
systemextensionsctl list -
Opens a man page in a separate Mac Terminal window so your prompt stays free.
open x-man-page://rsync -
Print the chip name, memory size and core count with one short command.
sysctl -n machdep.cpu.brand_string hw.memsize hw.ncpu -
Puts the complete, escaped path of a Finder item on your command line.
cd /Users/me/Downloads/Old\ Projects\ 2024 -
Names a terminal tab or window from the command line or from a script.
printf '\033]0;%s\007' "deploy running" -
Re-index a single folder or test what Spotlight extracts from one file.
mdimport -i ~/Documents/Invoices -
Read a single key such as an app's version from a property list file.
/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" /Applications/Safari.app/Contents/Info.plist -
Finds the command you need when you only know what it should do.
man -k checksum -
Wipes the whole scrollback in Terminal on a Mac instead of just the visible screen.
clear && printf '\033[3J' -
Check in one line that System Integrity Protection still guards your Mac.
csrutil status -
Lets the Option key act as Alt for word jumps and other shell shortcuts.
[x] Use Option as Meta key -
Get an app's bundle identifier for defaults, profiles or scripts in one line.
osascript -e 'id of app "Safari"' -
Read your account's home folder, shell and user ID straight from the directory.
dscl . -read /Users/$USER NFSHomeDirectory UserShell UniqueID -
Resolve a home or lab domain with a specific server while everything else stays unchanged.
sudo mkdir -p /etc/resolver -
Look back through recent system log entries for one process instead of streaming.
/usr/bin/log show --last 1h --style compact --predicate 'process == "softwareupdated"' -
Breaks down the memory footprint of a process into categories, with optional sampling.
footprint Safari -
Lists the file system calls of one app live, so you see which files it touches.
sudo fs_usage -w -f filesys Mail -
Streams the macOS unified log live, filtered to one process or subsystem.
log stream --predicate 'process == "Finder"' --style compact -
Lists the queued print jobs and printer status from the Mac terminal.
lpstat -o -
Applies real or simulated low-memory states to a Mac, for a set number of seconds.
memory_pressure -S -l warn -s 20 -
Creates a file of an exact size, optionally without allocating the disk space.
mkfile -v 100m /tmp/test-100m.bin -
Launches another instance of an app that is already running.
open -n -a Calculator -
Prints the status of the batteries and power sources of a MacBook from Terminal.
pmset -g batt -
Records where a running or frozen app spends its time, as a text call tree.
sample Safari 5 -file ~/Desktop/safari-sample.txt -
Runs a command or an already running process at low background priority.
taskpolicy -b ./convert-all.sh -
Shows the processes with the biggest memory footprint first, in a fixed-size list.
top -o mem -n 10 -
Prints macOS memory statistics in pages, with the page size in the header.
vm_stat -
Previews which processes a killall command would hit without sending any signal.
killall -s Finder -
Opens files in a specific app from the terminal, without changing your default app.
open -a Preview *.png -
Lists the recent sleep and wake events of your Mac to explain battery drain.
pmset -g log | grep -i wake -
Schedules your Mac to wake, start, sleep or shut down at fixed times.
sudo pmset repeat wakeorpoweron MTWRF 07:45:00 sleep MTWRFSU 23:30:00 -
Downloads a chosen macOS installer version from Terminal instead of the App Store.
softwareupdate --list-full-installers -
Installs Rosetta for Intel apps from Terminal, ready for scripts on a new Mac.
softwareupdate --install-rosetta -
Jumps between command prompts in Terminal and selects one command's output.
Command-Up Arrow jump to previous mark -
Converts a plain text file to a PDF from the terminal, using the Mac's print system.
cupsfilter notes.txt > notes.pdf -
Makes a USB drive that can boot a Mac and install macOS from it.
sudo /Applications/Install\ macOS\ 27\ Golden\ Gate.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume -
Stores a password in the macOS keychain and reads it back in a script, without a plain text file.
security add-generic-password -a "$USER" -s myapi -w -
Calculates the SHA-256 of a file on a Mac, or checks it against a list of checksums.
shasum -a 256 ~/Downloads/debian-13.iso -
Shows the model, chip, memory and serial number of a Mac from the terminal.
system_profiler SPHardwareDataType -
Lists what a .pkg installer added to your Mac, so you can see where its files went.
pkgutil --pkgs -
Runs your Shortcuts app shortcuts from the command line, with files as input.
shortcuts run "Combine Images" -i ~/Desktop/*.jpg -o ~/Desktop/combined.png -
Plays an audio file through the default output, so a long command can tell you it has finished.
afplay /System/Library/Sounds/Glass.aiff -
Lists installed formulae that no other installed formula or cask depends on.
brew leaves -
Reads text out loud with a system voice, or writes the speech to an audio file.
say -v '?' -
Prints the macOS product name, version and build number, or just one of them for scripts.
sw_vers -
Measures your download and upload speed and the lag under load, without opening a browser.
networkQuality -
Lists the macOS updates that are waiting for you, straight from the terminal.
softwareupdate --list -
Sends the output of a terminal command straight to the clipboard, so you can paste it anywhere.
cat ~/.ssh/id_ed25519.pub | pbcopy -
Keeps your Mac awake only while one long command runs, then lets it sleep again.
caffeinate -i rsync -a ~/Photos /Volumes/backup/ -
Prints a macOS preferences file as readable text.
plutil -p ~/Library/Preferences/com.apple.finder.plist -
Lists the updates Apple has ready for your Mac, from the terminal.
softwareupdate --list -
Takes a screenshot after a few seconds so you can open menus first.
screencapture -T 5 ~/Desktop/menu.png -
Shows whether Spotlight indexing is on for a disk.
mdutil -s / -
Lists which programs are stopping your Mac from going to sleep.
pmset -g assertions
Nothing in this filter yet.