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:

CommandDescriptionExampleWindows Equivalent
pwdPrint working directorypwdcd (without args)
lsList directory contentslsdir
ls -laList all files with detailsls -ladir /a
ls -GList with colors (BSD)ls -Gdir with colors
cd [dir]Change directorycd Documentscd [dir]
cd ~Go to home directorycd ~cd %USERPROFILE%
cd /Go to root directorycd /cd \
clearClear terminal screenclearcls
treeDisplay directory treetree (if installed)tree
open .Open current dir in Finderopen .start .

Exercise 1: Navigation Practice

Part 3: File Management Commands

File Operations:

CommandDescriptionExample
touch [file]Create empty filetouch newfile.txt
echo "text" > fileCreate file with contentecho "Hello Mac" > greeting.txt
cat [file]Display file contentscat file.txt
less [file]View file page by pageless largefile.txt
head -n [num] [file]View first n lineshead -n 10 file.txt
tail -n [num] [file]View last n linestail -n 10 file.txt
cp [src] [dest]Copy filecp file.txt backup.txt
mv [src] [dest]Move/rename filemv old.txt new.txt
rm [file]Remove filerm unwanted.txt
rm -i [file]Remove with confirmationrm -i important.txt
open [file]Open file with default appopen document.pdf
open -a [app] [file]Open with specific appopen -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:

CommandDescriptionExample
open [file/dir]Open with default applicationopen image.jpg
open -a [app]Open specific applicationopen -a "Visual Studio Code"
pbcopyCopy to clipboardcat file.txt | pbcopy
pbpastePaste from clipboardpbpaste > newfile.txt
say [text]Text-to-speechsay "Hello world"
screencaptureTake screenshotscreencapture -x ~/Desktop/shot.png
mdfind [query]Spotlight search from terminalmdfind "kind:image"
mdls [file]Show file metadatamdls photo.jpg
ditto [src] [dest]Copy preserving metadataditto source/ dest/
diskutil listList all disksdiskutil list
caffeinatePrevent sleepcaffeinate -t 3600 (1 hour)
pmsetPower managementpmset -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)"
CommandDescriptionExample
brew install [package]Install packagebrew install git
brew uninstall [package]Remove packagebrew uninstall git
brew updateUpdate Homebrewbrew update
brew upgradeUpgrade all packagesbrew upgrade
brew listList installed packagesbrew list
brew search [term]Search for packagesbrew search node
brew info [package]Package informationbrew info git
brew cleanupRemove old versionsbrew cleanup
brew doctorCheck for issuesbrew doctor

Popular packages to install:

  • brew install git - Version control
  • brew install node - Node.js and npm
  • brew install python - Latest Python
  • brew install tree - Directory tree viewer
  • brew install wget - File downloader
  • brew install htop - Better process viewer
  • brew install --cask visual-studio-code - GUI apps

Part 6: System Information & Monitoring

CommandDescriptionExample
uname -aSystem informationuname -a
sw_versmacOS version infosw_vers
system_profilerDetailed system infosystem_profiler SPHardwareDataType
topProcess monitortop (q to quit)
activity monitorOpen Activity Monitoropen -a "Activity Monitor"
df -hDisk space usagedf -h
du -sh [dir]Directory sizedu -sh ~/Downloads
ps auxRunning processesps aux | grep Chrome
uptimeSystem uptimeuptime
whoLogged in userswho

Part 7: Network Commands

CommandDescriptionExample
ping [host]Test network connectivityping google.com
curl [url]Transfer data from servercurl https://api.github.com
wget [url]Download files (via Homebrew)wget https://example.com/file.zip
netstat -anNetwork connectionsnetstat -an | grep LISTEN
lsof -iNetwork processeslsof -i :80
nslookup [domain]DNS lookupnslookup google.com
traceroute [host]Trace network pathtraceroute google.com
networksetupNetwork configurationnetworksetup -listallhardwareports

Quick Reference Card

Essential macOS Commands
  • open . - Open in Finder
  • open -a App file - Open with app
  • pbcopy - Copy to clipboard
  • pbpaste - Paste from clipboard
  • say "text" - Text to speech
  • mdfind query - Spotlight search
File Operations
  • ls -laG - List with colors
  • touch file - Create file
  • cat file - View file
  • cp src dest - Copy
  • mv src dest - Move
  • rm file - Delete
Terminal Shortcuts
  • Cmd+T - New tab
  • Cmd+W - Close tab
  • Cmd+K - Clear screen
  • Cmd+Plus/Minus - Font size
  • Cmd+D - Split vertically
  • Cmd+Shift+D - Split horizontally
Environment Variables
  • echo $HOME - Home directory path
  • echo $PATH - Executable paths
  • echo $USER - Current username
  • export VAR=value - Set environment variable
Aliases in ~/.zshrc (or ~/.bash_profile)
  • alias ll='ls -laG' - Long list with colors
  • alias ..='cd ..' - Go up one directory
  • alias desk='cd ~/Desktop' - Quick to Desktop
  • alias 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 tools
  • git --version - Check Git installation
  • gcc --version - C compiler
  • make --version - Build automation
Popular Development Commands
  • git clone [repo] - Clone repository
  • npm install - Install Node.js packages
  • python3 -m http.server - Quick web server
  • code . - Open VS Code in current directory
File Permissions (BSD style)
  • chmod +x script.sh - Make executable
  • chmod 755 file - Set permissions
  • chown user:group file - Change ownership
  • ls -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.