macOS Terminal / iTerm2 Cheat Sheet
The default macOS shell is zsh (config in ~/.zshrc). Most Linux commands work too; see the Bash sheet. This page covers the Mac-specific parts.
On this page
Terminal.app Shortcuts #
| Shortcut | Action |
|---|---|
⌘ N / ⌘ T | New window / new tab |
⌘ W | Close tab |
⌘ ⇧ [ / ⌘ ⇧ ] | Previous / next tab |
⌘ K | Clear the screen and scrollback |
⌘ D | Split the window (view the scrollback of the same shell) |
⌘ F | Find |
⌘ + / ⌘ - | Bigger / smaller text |
⌥ + click | Move the cursor to the clicked position |
⌘ . | Interrupt (same as ⌃ C) |
iTerm2 Shortcuts #
| Shortcut | Action |
|---|---|
⌘ D | Split pane vertically (side by side) |
⌘ ⇧ D | Split pane horizontally (stacked) |
⌘ [ / ⌘ ] | Previous / next pane |
⌘ ⌥ ←/→/↑/↓ | Move to the pane in that direction |
⌘ ⇧ Enter | Maximize / restore the current pane |
⌘ Enter | Full screen |
⌘ ; | Autocomplete from words on screen |
⌘ ⇧ H | Paste history |
⌘ ⇧ ; | Command history (requires shell integration) |
⌘ / | Highlight the cursor position |
⌘ ⌥ B | Instant replay (scroll back in time) |
⌘ ⌥ I | Broadcast input to all panes |
⌘ , | Preferences (set a Hotkey Window for a drop-down terminal) |
Mac-Only Commands #
| Command | Action |
|---|---|
| Open the current folder in Finder | |
| Open with the default app | |
| Open with a specific app | |
| Copy file content to the clipboard | |
| Paste the clipboard into a file | |
| Text to speech | |
Keep the Mac awake (until ⌃ C) | |
| Spotlight search from the terminal | |
| Quick Look preview | |
| Interactive screenshot | |
| macOS version | |
| Disks and partitions | |
| List system updates | |
| Install command-line developer tools (git, make, clang) | |
| Always show hidden files |
Homebrew (package manager) #
| Command | Action |
|---|---|
| Install a CLI tool | |
| Install a GUI app | |
| Search | |
| Installed packages | |
| Update Homebrew and all packages | |
| Remove | |
| Remove old versions | |
| Diagnose problems | |
| Run a service in the background |
zsh Tips #
| Feature | How |
|---|---|
| Config file | ~/.zshrc, reload with |
| Alias | |
| Change folder without | Type the folder name (with setopt autocd) |
| Recursive glob | |
| Oh My Zsh | Themes and plugins (git, autosuggestions…) |
Tips #
- Drag a file or folder from Finder into the terminal to paste its path.
- In iTerm2 set Profiles → Keys → Left Option key to Esc+ so
⌥ ←/→jumps words. ⌃ A/⌃ E(start / end of line) and⌃ R(history search) work in zsh just like in Bash.
openOpen files, folders, apps and URLs like a double-click. open [options] file|folder|URL
| Option | What it does |
|---|---|
open . | Open the current folder in Finder |
open file.pdf | Open with the default app |
open https://github.com | Open in the default browser |
-a "App Name" | Open with a specific app: open -a "Visual Studio Code" . |
-b com.apple.TextEdit | Open with an app by bundle id |
-e | Open in TextEdit |
-t | Open in the default text editor |
-R | Reveal the file in Finder (select it) |
-n | Start a new instance of the app |
-g | Open in the background (don't switch to it) |
-j | Launch hidden |
-W | Wait until the app is closed (scripts) |
-F | Fresh: don't restore the app's windows |
--args … | Pass arguments to the app |
pbcopyalso: pbpasteCopy to and paste from the macOS clipboard.
| Usage / option | What it does |
|---|---|
pbcopy < file.txt | Copy a file's contents |
echo hi | pbcopy | Copy command output |
pbpaste > file.txt | Paste the clipboard into a file |
pbpaste | wc -w | Use the clipboard as input |
pbpaste -Prefer txt | Prefer plain text (rtf or ps also possible) |
-pboard find | Use another pasteboard (general, ruler, find, font) |
sayText to speech. say [options] "text"
| Option | What it does |
|---|---|
-v Samantha | Choose a voice (say -v '?' lists them) |
-r 200 | Speed in words per minute |
-f file.txt | Read a text file aloud |
-o speech.aiff | Save to an audio file instead of playing |
-i | Highlight words while speaking |
Handy after a long job: npm run build && say "Build done".
caffeinateKeep the Mac awake. caffeinate [options] [command]
| Option | What it does |
|---|---|
| (none) | Prevent idle sleep until Ctrl + C |
-d | Keep the display on |
-i | Prevent idle sleep |
-m | Prevent the disk from sleeping |
-s | Prevent system sleep (on AC power) |
-u | Pretend the user is active (wakes the display) |
-t 3600 | Only for 1 hour |
-w 1234 | Until process 1234 ends |
caffeinate -i npm run build | Stay awake while a command runs |
mdfindSpotlight search from the terminal. mdfind [options] query
| Option | What it does |
|---|---|
mdfind invoice | Files whose content or metadata matches |
-name report | Match the file name only |
-onlyin ~/Documents | Search only in a folder |
-count | Only the number of results |
-live | Keep updating as files change |
-0 | Null-separated output (for xargs -0) |
'kMDItemContentType == "public.image"' | Metadata query (all images) |
qlmanageQuick Look from the terminal. qlmanage [options] file
| Option | What it does |
|---|---|
-p file | Preview a file (like pressing Space in Finder) |
-t file | Make a thumbnail |
-s 512 | Thumbnail size (with -t) |
-o folder | Where to save thumbnails |
-r | Reload the Quick Look plugins |
-r cache | Reset the thumbnail cache |
screencaptureScreenshots and recordings from the terminal. screencapture [options] [file]
| Option | What it does |
|---|---|
-i | Interactive: select an area (Space = window) |
-w | Window mode (with -i) |
-s | Selection mode only (with -i) |
-c | Copy to the clipboard instead of a file |
-T 5 | Wait 5 seconds first |
-x | No camera sound |
-o | No window shadow |
-C | Include the mouse cursor |
-R x,y,w,h | Capture a rectangle |
-t jpg | Image format (png, jpg, pdf, tiff) |
-v | Record video (-V 10 = 10 seconds) |
-P | Open the result in Preview |
sw_versShow the macOS version.
| Option | What it does |
|---|---|
| (none) | Product name, version and build |
-productName | macOS |
-productVersion | 15.1 |
-buildVersion | 24B83 |
diskutilDisks, partitions and volumes. diskutil verb [options]
| Verb | What it does |
|---|---|
list | All disks and partitions |
info disk2 | Details of a disk or volume |
apfs list | APFS containers and volumes |
mountDisk disk2 / unmountDisk disk2 | Mount / unmount every volume on a disk |
eject disk2 | Eject safely |
verifyVolume / | Check a volume for errors |
repairVolume disk2s1 | Repair a volume |
eraseDisk APFS Name disk2 | ⚠ Erase a whole disk (JHFS+, ExFAT, FAT32…) |
eraseVolume ExFAT Name disk2s1 | ⚠ Erase one volume |
partitionDisk disk2 GPT … | Partition a disk |
Always double-check the disk number with diskutil list before erasing.
softwareupdatemacOS updates from the terminal. softwareupdate [options]
| Option | What it does |
|---|---|
-l, --list | List available updates |
-i -a | Install all updates |
-i "Label" | Install one update (label from --list) |
-d | Download only |
-R | Restart automatically when needed |
--history | Updates installed so far |
--fetch-full-installer | Download the full macOS installer |
--install-rosetta --agree-to-license | Install Rosetta 2 (Apple silicon) |
xcode-selectCommand Line Tools (git, make, clang…). xcode-select [options]
| Option | What it does |
|---|---|
--install | Install the Command Line Tools |
-p | Print the active developer folder |
-s /Applications/Xcode.app | Switch to another Xcode / tools folder (sudo) |
--reset | Back to the default folder (sudo) |
-v | Version |
defaultsRead and write hidden macOS settings. defaults command domain [key] [value]
| Command | What it does |
|---|---|
read com.apple.finder | Show all settings of an app |
read com.apple.dock autohide | One setting |
write domain key -bool true | Set a value (-int, -float, -string, -array) |
delete domain key | Back to the default |
domains | All settings domains |
find word | Search every domain |
export domain file.plist / import | Back up / restore an app's settings |
Popular: defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder · defaults write com.apple.dock autohide-delay -float 0; killall Dock.
brewHomebrew package manager for macOS (and Linux). brew command [options]
| Command / option | What it does |
|---|---|
install name | Install a command-line tool |
install --cask name | Install a GUI app (firefox, visual-studio-code…) |
uninstall name | Remove (--zap also removes a cask's settings) |
search word | Search |
info name | Details, version, dependencies |
list | Installed packages (--cask, --versions) |
update | Update Homebrew's package lists |
upgrade | Upgrade everything (upgrade name for one, --greedy for self-updating casks) |
outdated | What can be upgraded |
cleanup | Remove old versions (--prune=all clears the whole cache) |
autoremove | Remove unneeded dependencies |
leaves | Packages you installed (nothing depends on them) |
deps --tree name / uses --installed name | Dependencies / reverse dependencies |
pin name / unpin name | Hold / release a version |
services list | Background services (start, stop, restart name) |
tap user/repo | Add a third-party repository |
doctor | Diagnose problems |
bundle dump / bundle install | Save / restore everything installed in a Brewfile |
sourceRun a script in the current shell, so its variables, aliases and functions stay. source file [args]
| Usage | What it does |
|---|---|
source ~/.bashrc | Reload your Bash settings after editing them |
. ~/.bashrc | Same: . is the POSIX spelling of source |
source .venv/bin/activate | Activate a Python virtual environment |
source .env | Load KEY=value lines as shell variables |
set -a; source .env; set +a | …and export them to programs you start |
aliasalso: unaliasShortcuts for commands (Bash / zsh). Put them in ~/.bashrc or ~/.zshrc to keep them.
| Usage | What it does |
|---|---|
alias | List all aliases (alias -p in reusable form) |
alias ll='ls -la' | Create an alias (no spaces around =) |
alias gs='git status' | Shortcut for a longer command |
unalias ll | Remove an alias (unalias -a = all) |
\ls | Run the real command once, ignoring an alias |
type ll | Show what an alias expands to |
cdChange the current folder. cd [path]
| Usage | What it does |
|---|---|
cd folder | Go into a folder (relative to where you are) |
cd /var/log | Go to an absolute path |
cd .. | One folder up (cd ../.. = two up) |
cd or cd ~ | Your home folder |
cd - | Back to the previous folder |
cd / | The root of the filesystem |
cd "My Folder" | Paths with spaces need quotes (or My\ Folder) |
-P | Resolve symbolic links to the real path |
-L | Follow symbolic links as they are (default) |
Git Bash: drives are /c/, /d/… WSL: Windows drives are under /mnt/c/.
lsList the files and folders in a directory. ls [options] [path…]
| Option | What it does |
|---|---|
-l | Long list: permissions, owner, size, date |
-a, --all | Also show hidden files (names starting with .) |
-A, --almost-all | Hidden files too, but without . and .. |
-h, --human-readable | Sizes like 4.0K, 12M, 1.1G (use with -l) |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-X | Sort by file extension |
-v | Natural sort of numbers (file2 before file10) |
-r, --reverse | Reverse the sort order |
-R, --recursive | List all subfolders too |
-d | List the folder itself, not what's inside (ls -d */ = only folders) |
-1 | One name per line |
-F, --classify | Add / after folders, * after executables, @ after links |
-i | Show inode numbers |
-n | Numeric user and group IDs |
-s | Show the allocated size of each file |
--color=auto | Colour output (always / never) |
--group-directories-first | Folders before files |
--time-style=long-iso | Dates as 2026-10-01 14:05 |
--sort=WORD | Sort by size, time, extension, version or none |
Popular combinations: ls -la (everything, detailed) · ls -lah (+ readable sizes) · ls -lt (newest first) · ls -lS (biggest first).
macOS: -G enables colour; the long --options don't exist there. Full list: man ls or ls --help.
Nothing on this sheet matches “”.