Tutorial 05 · macOS

Terminal basics

Get comfortable in Terminal: the zsh shell, paths, your PATH and a handful of genuinely useful commands.

Last updated

Terminal (in Applications > Utilities, or Command+Space then Terminal) gives you a command line. The default shell is zsh. You don't need it for daily use, but it makes some jobs much faster.

1Paths and moving around

Your home folder is ~ (/Users/yourname). Absolute paths start with /; relative paths start from where you are. Paths with spaces need quotes or backslashes. Tip: drag a file from the Finder into Terminal to paste its path.

pwd                    # where am I?
ls -la                 # list files, including hidden ones
cd ~/Documents
cd ..                  # up one level
cd "~/My Folder"       # wrong: ~ isn't expanded inside quotes
cd ~/"My Folder"       # right

2Files and folders

mkdir -p ~/Projects/test
cp report.pdf ~/Desktop/
mv old-name.txt new-name.txt
rm file.txt            # deletes immediately, no Bin
open .                 # open this folder in the Finder
open -a TextEdit notes.txt

3Your shell configuration and PATH

zsh reads ~/.zprofile for login shells (each new Terminal window) and ~/.zshrc for interactive shells. PATH is the list of folders searched for commands; macOS builds the default from /etc/paths and /etc/paths.d.

echo $PATH
which python3
# add your own folder to PATH, then reload
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

4Handy macOS commands

man ls                 # manual page (q to quit)
mdfind "invoice 2026"  # Spotlight search from the shell
pbcopy < notes.txt     # copy a file's contents to the clipboard
pbpaste > clip.txt
caffeinate -d          # keep the display awake until Control-C
sw_vers                # macOS version
softwareupdate --list
du -sh ~/Downloads     # how big is a folder?
top -o cpu             # what's using the CPU (q to quit)

5Using sudo carefully

sudo runs one command as the administrator after asking for your password. Only use it when a command really needs it, and double-check the command first, especially anything with rm. System Integrity Protection stops even sudo from changing core system files.

← All macOS tutorials