These are the Terminal commands I use most on a Mac, grouped by task, with exact syntax and an example for each. macOS ships BSD versions of most of them, so some Linux flags fail here.
I ran the examples on 2026-10-04 on macOS 26.6 (build 25G72, Apple silicon) and only read the man pages for sudo, ssh, scp, open, pbcopy, trash, kill, killall and brew install. Apple released macOS 27 Golden Gate on 14 September 2026; I have not tested these on it.
Table of Contents
Navigate folders in Terminal
| Command | What it does | Example |
|---|---|---|
pwd |
Print the current folder | pwd |
cd |
Change folder; cd .. goes up (cd - returns to the previous one, and pwd can disagree with pwd -P) |
cd /Applications && pwd |
ls |
List files; -l long, -a hidden, -h readable sizes |
ls -lah |
open |
Open a file, app or URL; open . shows this folder in Finder |
open -a Preview report.pdf |
man |
Manual page (q quits); ls --help fails on macOS |
man ls |
history |
Recent commands; zsh shows the last 16, history 1 shows all |
history 1 | grep ssh |
From Apple’s Terminal User Guide: Control-C stops the running command, the Up Arrow recalls the previous one, and dragging a file or folder from Finder into the window types its path.
Create, copy, move, read and delete files
| Command | What it does | Example |
|---|---|---|
mkdir / rmdir |
Make a folder (-p makes parents) / remove an empty one |
mkdir -p d1/d2 |
touch |
Create an empty file or update its modification time | touch filename.txt |
cp |
Copy; -R for folders; a trailing / copies only the contents |
cp -R d1/ d2copy/ |
mv |
Move or rename | mv dest.txt renamed.txt |
rm |
Delete at once, no Trash; -r for folders |
rm renamed.txt |
trash |
Move to the Trash (macOS 15 and later) | trash renamed.txt |
cat / head / tail |
Whole file / first 10 / last 10 lines; tail -f follows |
tail -n 2 bigfile.txt |
less |
Page through a file: Space, / to search, q to quit |
less bigfile.txt |
pbcopy / pbpaste |
Standard input to the clipboard / clipboard to output | pbcopy < source.txt |
Search for files and text
| Command | What it does | Example |
|---|---|---|
find |
Search by name; BSD find needs a starting folder |
find . -name "*.txt" |
grep |
Search inside files; -i ignores case, -n numbers lines, -r recurses; no -P |
grep -rn "hello" . |
mdfind |
Spotlight search; -name matches file names |
mdfind -name report.pdf |
Check and stop processes
| Command | What it does | Example |
|---|---|---|
ps aux |
Every running process | ps aux | grep -i safari |
top |
Live view; -o mem sorts by memory, q quits |
top -o mem |
kill |
Signal a process by ID; -9 forces it |
kill 38914 |
killall |
Signal your processes by name; -s only previews |
killall Safari |
Network commands
| Command | What it does | Example |
|---|---|---|
ping |
Reachability test; -c sets the count |
ping -c 4 example.com |
curl |
Fetch a URL; -I headers only, -O saves the file |
curl -I https://example.com |
ifconfig |
Show network interfaces | ifconfig |
ipconfig / networksetup |
An interface’s IPv4 address / ports and their device names (networksetup also changes settings) |
ipconfig getifaddr en0networksetup -listallhardwareports |
ssh / scp |
Remote shell / copy over SSH | ssh user@hostscp report.pdf user@host:~/ |
Check disk space
| Command | What it does | Example |
|---|---|---|
df -h |
Free space on each volume | df -h |
du |
Folder size; -s total, -d 1 one level down (--max-depth fails) |
du -sh .du -h -d 1 |
diskutil |
List disks / details of one | diskutil listdiskutil info / |
Change permissions and ownership
| Command | What it does | Example |
|---|---|---|
ls -l |
Owner, group and permission bits | ls -l script.sh |
chmod |
Change permissions; Apple’s Terminal guide uses 755 |
chmod +x script.shchmod 755 source.txt |
chown |
Change owner; giving a file away needs sudo |
chown "$(id -un):staff" source.txt |
sudo |
Run one command as root | sudo nano /etc/hosts |
Show system information and software
| Command | What it does | Example |
|---|---|---|
sw_vers |
macOS version and build | sw_vers |
uname -m |
CPU architecture; arm64 on Apple silicon |
uname -m |
system_profiler |
Model, chip and memory | system_profiler SPHardwareDataType |
caffeinate |
Keep the display awake; -t is in seconds |
caffeinate -d -t 3600 |
brew |
Homebrew. Never with sudo |
brew install --dry-run wget |
Common Terminal errors on a Mac
| Message | Cause | Fix |
|---|---|---|
zsh: command not found: name |
Misspelled, not installed, or not on PATH |
Check the spelling and run command -v name. For brew on Apple silicon, add eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zshrc |
zsh: no matches found: *.txt |
A wildcard matched nothing; zsh also treats ? in a URL as one |
Quote it: curl "https://example.com/?a=1" |
zsh: permission denied: ./script.sh |
Not executable | chmod +x script.sh |
Operation not permitted |
macOS privacy protection, System Integrity Protection, or chown to another user without sudo |
Add your terminal app under System Settings > Privacy & Security > Full Disk Access. Leave the folders System Integrity Protection guards (/System, /usr except /usr/local, /bin, /sbin, /var) alone |
cd: string not in pwd: My |
Unquoted space: zsh read cd My Documents as cd old new |
cd "My Documents" |
du: unrecognized option, grep: invalid option -- P, find: illegal option -- n |
A GNU-only flag, or find without a folder |
Use du -d 1, grep -E, find . -name x. sed -i needs an extension: sed -i .bak 's/a/b/' file |
Commands that are not what you expect on macOS
sudo apt-get update. apt-get is Debian’s package manager and does not exist on macOS:
$ command -v apt-get
$ echo $?
1
macOS has two equivalents: softwareupdate for Apple software, and Homebrew for third-party command-line software:
softwareupdate --list # ran here, no sudo required
brew update && brew upgrade # updates Homebrew AND its formula index, then packages
Homebrew installs into a prefix you own, so it needs no sudo after its first install. The owner column shows it:
$ brew --prefix
/opt/homebrew
$ ls -ld /opt/homebrew
drwxr-xr-x ... [user] admin /opt/homebrew
Run as root, Homebrew 7.0.7 stops with “Running Homebrew as root is extremely dangerous and no longer supported.” Its FAQ says builds and installations run as the owning account so build scripts do not get unrestricted system access.
nano is not GNU nano on macOS. It is a symlink:
$ ls -l /usr/bin/nano
lrwxr-xr-x 1 root wheel 4 Jul 22 16:57 /usr/bin/nano -> pico
Running nano --version opens a full-screen editor showing UW PICO 5.09 rather than a version, because pico spells the flag with one dash: nano -version prints Pico 5.09. vim is genuine — VIM - Vi IMproved 9.1 ships with the OS.
The history -c trap
Advice to clear your shell history with history -c comes from bash. macOS has used zsh as the default shell since Catalina (Apple’s support page on the default shell), and zsh’s history builtin does not have that option:
$ bash -c 'history -c'; echo $?
0
$ zsh -c 'history -c'
zsh:history:1: bad option: -c
$ echo $?
1
On zsh, the history lives in a file that macOS’s own /etc/zshrc configures on line 16 (macOS 26.6):
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
Truncating that file clears what earlier windows saved, but every open Terminal window, including the one you run it in, appends its commands back when its shell exits, and Terminal keeps a copy per window in ~/.zsh_sessions (/etc/zshrc_Apple_Terminal does both). To keep the history elsewhere, set HISTFILE in your own ~/.zshrc, which zsh reads after /etc/zshrc, and add SHELL_SESSION_HISTORY=0; with HISTFILE alone, Terminal still appends to ~/.zsh_history.
Two things worth setting up once
alias ll='ls -la' # add to ~/.zshrc, not ~/.bash_profile
export PS1='\u@\h \W $ ' # bash prompt; zsh uses PROMPT and %-escapes
Your interactive shell reads ~/.zshrc, so an alias in ~/.bash_profile, as older pages advise, works only in a bash session you started deliberately. Run echo $SHELL before deciding which file to edit.