TExcelTAD
Home › Terminal & Command Line › The Terminal on macOS

The Terminal on macOS

macOS is a certified UNIX system underneath its graphical interface. Its kernel (XNU) and command-line tools come from the BSD family, so the terminal feels almost like Linux: the same ls, cd, grep, ssh, pipes and redirection. Since macOS Catalina (10.15), the default shell is zsh; older Macs used bash 3.2, which Apple still ships at /bin/bash but never updates.

Terminal apps

App Notes
Terminal (built in) Applications → Utilities → Terminal, or Cmd+Space and type "Terminal". Tabs, profiles ("Settings… → Profiles"), good enough for most people
iTerm2 free, very popular: split panes, search, hotkey window, triggers, shell integration
Ghostty, WezTerm, Alacritty, kitty fast GPU-rendered terminals, configured with text files
Warp terminal with AI features and block-based output
VS Code / JetBrains built-in terminal panel running the same zsh

All of them start the same shell, so commands and your ~/.zshrc work identically in each.

Keyboard essentials

Keys Terminal.app iTerm2
New tab / window Cmd+T / Cmd+N same
Split pane (not available) Cmd+D vertical, Cmd+Shift+D horizontal
Copy / paste Cmd+C / Cmd+V same
Clear screen Cmd+K same
Stop the running command Ctrl+C same
Jump word by word Option+←/→ same
Move cursor with the mouse Option+click same

To use Option as the Alt/Meta key (for shortcuts like Alt+.), enable "Use Option as Meta key" in Terminal's profile settings (iTerm2: Profiles → Keys → "Esc+").

Drag and drop: dragging a file from Finder into the terminal pastes its full, escaped path.

The default prompt

macOS's zsh prompt shows user@computer folder %. It is defined by the PROMPT variable with escape codes, and you can preview any prompt with print -P:

zsh · try it yourself
PROMPT='%n@%m %1~ %# '
print -P "$PROMPT"
print -P '%B%n%b in %~ (exit status: %?)'
mkdir -p projects/site && cd projects/site
print -P 'Now: %n@%m %1~ %# '
print "zsh version: $ZSH_VERSION"
learner@tad ~ %
learner in ~ (exit status: 0)
Now: learner@tad site %
zsh version: 5.9

%n is the user, %m the host name, %1~ the last folder (with ~ for home), %# shows % (or # for root), %? the exit status of the last command, and %B…%b switch bold on and off (invisible in the plain-text output). The playground runs zsh on Linux as user learner on host tad; on a Mac you would see something like ada@macbook ~ %. The zsh Essentials lesson shows how to customise it.

macOS-only commands

These commands connect the terminal to the Mac's GUI and system. They exist only on macOS (so they can't run in the Linux playground):

zsh
ada@macbook ~ % open .                          # this folder in Finder
ada@macbook ~ % open report.pdf                 # with the default app
ada@macbook ~ % open -a "Visual Studio Code" .  # with a specific app
ada@macbook ~ % ls | pbcopy                     # copy output to the clipboard
ada@macbook ~ % pbpaste | wc -l                 # read the clipboard
       12
ada@macbook ~ % say "Build finished"            # text to speech
ada@macbook ~ % caffeinate -i make              # keep the Mac awake while make runs
ada@macbook ~ % mdfind -name invoice.pdf        # Spotlight search from the terminal
/Users/ada/Documents/invoice.pdf
ada@macbook ~ % sw_vers
ProductName:		macOS
ProductVersion:		15.6
BuildVersion:		24G84

(sample output — yours will differ). defaults reads and writes app preferences, e.g. to show hidden files in Finder:

zsh
ada@macbook ~ % defaults write com.apple.finder AppleShowAllFiles -bool true
ada@macbook ~ % killall Finder

Two clipboard helpers are worth remembering on Linux and Windows too:

macOS Windows Linux (X11 / Wayland)
Copy output cmd | pbcopy cmd | clip (CMD) / Set-Clipboard xclip -sel clip / wl-copy
Paste pbpaste Get-Clipboard xclip -o -sel clip / wl-paste
Open with default app open file start file / Invoke-Item file xdg-open file

Developer tools and Homebrew

macOS doesn't ship git, make or a C compiler by default. The first time you type git, macOS offers to install the Command Line Tools; you can also trigger that directly:

zsh
ada@macbook ~ % xcode-select --install

Everything else usually comes from Homebrew, the community package manager. Its installer is one command from brew.sh. On Apple Silicon Macs, Homebrew lives in /opt/homebrew (on Intel Macs /usr/local), and the installer tells you to add a line to ~/.zprofile so its programs are on your PATH:

zsh
ada@macbook ~ % echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
ada@macbook ~ % brew install git node wget
ada@macbook ~ % brew upgrade
ada@macbook ~ % brew install --cask iterm2 visual-studio-code

--cask installs GUI apps. More in Package Managers.

Gotchas coming from Linux

  • BSD tools: sed -i, date -d, stat -c and other GNU options behave differently or don't exist. See BSD vs GNU Tools.
  • Old bash: /bin/bash is 3.2 (from 2007, the last GPLv2 version). Scripts using associative arrays or ${var,,} need brew install bash (it installs to /opt/homebrew/bin/bash).
  • Case-insensitive file system: APFS is case-insensitive by default, so README.md and readme.md are the same file. Git repositories with both will misbehave.
  • Quarantine: files downloaded from the internet get a com.apple.quarantine attribute; Gatekeeper may block unsigned tools. xattr -d com.apple.quarantine ./tool removes it for a tool you trust.
  • Login shells: every new Terminal window is a login shell, so both ~/.zprofile and ~/.zshrc run.

Learn more: zsh Essentials, BSD vs GNU Tools, Terminal Apps on Every OS.

Test yourself

What is the default shell on current versions of macOS?

  1. bash 5
  2. zsh
  3. fish
  4. tcsh

Which command copies the output of ls to the macOS clipboard?

  1. ls | clip
  2. ls | pbcopy
  3. ls > clipboard
  4. ls | Set-Clipboard

In the zsh prompt string %n@%m %1~ %# , what does %1~ show?

  1. The first command in history
  2. The last component of the current folder, with ~ for home
  3. The user ID
  4. The time