macOS Terminal Lab
Master macOS command line operations with Unix/BSD commands and Mac-specific features
Lab Overview
This lab teaches you essential macOS Terminal commands, combining Unix/BSD heritage with Mac-specific features. macOS Terminal provides powerful command-line tools for file management, system administration, and development work.
Prerequisites: macOS system with Terminal access
Note: macOS uses BSD-based commands which may differ slightly from Linux. Some commands require Xcode Command Line Tools.
Part 1: Opening Terminal
Methods to Open Terminal:
Quick Methods:
- Cmd + Space → Type "Terminal" → Enter
- Launchpad → Other → Terminal
- Applications → Utilities → Terminal
- Finder → Applications → Utilities → Terminal
Alternative Terminals:
- iTerm2 - Popular third-party terminal
- Hyper - Electron-based terminal
- Warp - Modern terminal with AI features
- Alacritty - GPU-accelerated terminal
Pro Tip: Pin Terminal to your Dock for quick access. Right-click Terminal in Dock → Options → Keep in Dock
Part 2: Navigation Commands
Essential Navigation Commands:
Command | Description | Example | Windows Equivalent |
---|---|---|---|
pwd | Print working directory | pwd | cd (without args) |
ls | List directory contents | ls | dir |
ls -la | List all files with details | ls -la | dir /a |
ls -G | List with colors (BSD) | ls -G | dir with colors |
cd [dir] | Change directory | cd Documents | cd [dir] |
cd ~ | Go to home directory | cd ~ | cd %USERPROFILE% |
cd / | Go to root directory | cd / | cd \ |
clear | Clear terminal screen | clear | cls |
tree | Display directory tree | tree (if installed) | tree |
open . | Open current dir in Finder | open . | start . |
Exercise 1: Navigation Practice
Part 3: File Management Commands
File Operations:
Command | Description | Example |
---|---|---|
touch [file] | Create empty file | touch newfile.txt |
echo "text" > file | Create file with content | echo "Hello Mac" > greeting.txt |
cat [file] | Display file contents | cat file.txt |
less [file] | View file page by page | less largefile.txt |
head -n [num] [file] | View first n lines | head -n 10 file.txt |
tail -n [num] [file] | View last n lines | tail -n 10 file.txt |
cp [src] [dest] | Copy file | cp file.txt backup.txt |
mv [src] [dest] | Move/rename file | mv old.txt new.txt |
rm [file] | Remove file | rm unwanted.txt |
rm -i [file] | Remove with confirmation | rm -i important.txt |
open [file] | Open file with default app | open document.pdf |
open -a [app] [file] | Open with specific app | open -a TextEdit file.txt |
Exercise 2: Complete macOS File Project
Project: Create a macOS development workspace with multiple files and practice all operations
Step 1: Setup Workspace
Step 2: Create Multiple Files
Step 3: Organize with Directories
Step 4: File Operations
Step 5: macOS-Specific Operations
Step 6: Cleanup (Optional)
Part 4: macOS-Specific Commands
Mac-Only Commands:
Command | Description | Example |
---|---|---|
open [file/dir] | Open with default application | open image.jpg |
open -a [app] | Open specific application | open -a "Visual Studio Code" |
pbcopy | Copy to clipboard | cat file.txt | pbcopy |
pbpaste | Paste from clipboard | pbpaste > newfile.txt |
say [text] | Text-to-speech | say "Hello world" |
screencapture | Take screenshot | screencapture -x ~/Desktop/shot.png |
mdfind [query] | Spotlight search from terminal | mdfind "kind:image" |
mdls [file] | Show file metadata | mdls photo.jpg |
ditto [src] [dest] | Copy preserving metadata | ditto source/ dest/ |
diskutil list | List all disks | diskutil list |
caffeinate | Prevent sleep | caffeinate -t 3600 (1 hour) |
pmset | Power management | pmset -g batt (battery info) |
Part 5: Package Management
Homebrew - The Missing Package Manager for macOS
Install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Command | Description | Example |
---|---|---|
brew install [package] | Install package | brew install git |
brew uninstall [package] | Remove package | brew uninstall git |
brew update | Update Homebrew | brew update |
brew upgrade | Upgrade all packages | brew upgrade |
brew list | List installed packages | brew list |
brew search [term] | Search for packages | brew search node |
brew info [package] | Package information | brew info git |
brew cleanup | Remove old versions | brew cleanup |
brew doctor | Check for issues | brew doctor |
Popular packages to install:
brew install git
- Version controlbrew install node
- Node.js and npmbrew install python
- Latest Pythonbrew install tree
- Directory tree viewerbrew install wget
- File downloaderbrew install htop
- Better process viewerbrew install --cask visual-studio-code
- GUI apps
Part 6: System Information & Monitoring
Command | Description | Example |
---|---|---|
uname -a | System information | uname -a |
sw_vers | macOS version info | sw_vers |
system_profiler | Detailed system info | system_profiler SPHardwareDataType |
top | Process monitor | top (q to quit) |
activity monitor | Open Activity Monitor | open -a "Activity Monitor" |
df -h | Disk space usage | df -h |
du -sh [dir] | Directory size | du -sh ~/Downloads |
ps aux | Running processes | ps aux | grep Chrome |
uptime | System uptime | uptime |
who | Logged in users | who |
Part 7: Network Commands
Command | Description | Example |
---|---|---|
ping [host] | Test network connectivity | ping google.com |
curl [url] | Transfer data from server | curl https://api.github.com |
wget [url] | Download files (via Homebrew) | wget https://example.com/file.zip |
netstat -an | Network connections | netstat -an | grep LISTEN |
lsof -i | Network processes | lsof -i :80 |
nslookup [domain] | DNS lookup | nslookup google.com |
traceroute [host] | Trace network path | traceroute google.com |
networksetup | Network configuration | networksetup -listallhardwareports |
Quick Reference Card
Essential macOS Commands
open .
- Open in Finderopen -a App file
- Open with apppbcopy
- Copy to clipboardpbpaste
- Paste from clipboardsay "text"
- Text to speechmdfind query
- Spotlight search
File Operations
ls -laG
- List with colorstouch file
- Create filecat file
- View filecp src dest
- Copymv src dest
- Moverm file
- Delete
Terminal Shortcuts
Cmd+T
- New tabCmd+W
- Close tabCmd+K
- Clear screenCmd+Plus/Minus
- Font sizeCmd+D
- Split verticallyCmd+Shift+D
- Split horizontally
Environment Variables
echo $HOME
- Home directory pathecho $PATH
- Executable pathsecho $USER
- Current usernameexport VAR=value
- Set environment variable
Aliases in ~/.zshrc (or ~/.bash_profile)
alias ll='ls -laG'
- Long list with colorsalias ..='cd ..'
- Go up one directoryalias desk='cd ~/Desktop'
- Quick to Desktopalias finder='open .'
- Open current dir in Finder
Bonus: Development Tools
Xcode Command Line Tools
Essential development tools for macOS:
xcode-select --install
- Install command line toolsgit --version
- Check Git installationgcc --version
- C compilermake --version
- Build automation
Popular Development Commands
git clone [repo]
- Clone repositorynpm install
- Install Node.js packagespython3 -m http.server
- Quick web servercode .
- Open VS Code in current directory
File Permissions (BSD style)
chmod +x script.sh
- Make executablechmod 755 file
- Set permissionschown user:group file
- Change ownershipls -l
- View permissions
Pro Tip: Use
man [command]
to read manual pages for any command. macOS manual pages include BSD-specific information. Press q
to quit.