Essential macOS Terminal Commands
Unlock the power of the command line! Terminal gives you direct access to your Mac's Unix foundation.
Opening Terminal
- Applications → Utilities → Terminal
- Or:
⌘ + Space, type "terminal", press Enter
1. Navigation Commands
Print Working Directory - Shows your current folder location
List - Shows files in current directory
ls -la- Shows all files including hidden, with detailsls -lh- Shows file sizes in human-readable format
Change Directory - Navigate to Desktop
cd ~- Go to home directorycd ..- Go up one foldercd /- Go to root directory
2. File Operations
Make Directory - Creates new folder
Touch - Creates empty file
Copy - Duplicates a file
cp -r folder/ newfolder/- Copy entire folder
Move/Rename - Moves or renames file
Remove - Deletes file (permanent!)
rm -rf foldername/- Delete folder and contents (use carefully!)
3. Viewing Files
Concatenate - Displays file contents
Less - View file page by page (press Q to quit)
Head - Show first 10 lines of file
Tail - Show last 20 lines of file
4. System Information
Top - Shows running processes (like Activity Monitor)
Press Q to quit
Disk Free - Shows disk space usage
Disk Usage - Shows size of each item in current folder
System Profiler - Hardware information
5. Network Commands
Ping - Test network connectivity
Press Control + C to stop
Interface Config - Shows network interface info
Network Statistics - Shows network connections
6. Process Management
Process Status - Lists all running processes
Kill - Stops process with ID 1234
kill -9 1234- Force kill processkillall Safari- Kill all Safari processes
7. File Permissions
Change Mode - Modify file permissions
chmod +x script.sh- Make file executable
Change Owner - Change file ownership
8. Search Commands
Find - Search for files by name
Grep - Search inside files for text
grep -r "term" folder/- Search recursively in folder
9. Useful Shortcuts
Clear - Clears terminal screen (or: ⌘ + K)
History - Shows command history
Bang Bang - Repeats last command
Sudo - Run command as administrator
Will ask for your password
10. macOS Specific Commands
Open - Opens current folder in Finder
open file.pdf- Opens file in default appopen -a Safari- Opens Safari
killall Finder
Defaults - Show hidden files in Finder
Change TRUE to FALSE to hide again
Power Management - Shows battery status
Caffeinate - Prevents Mac from sleeping
Press Control + C to stop
11. Advanced Maintenance
Purge - Clears RAM cache (frees memory)
Periodic - Runs system maintenance scripts
Disk Utility - Lists all disks
Verify Volume - Checks disk for errors
12. Tips & Tricks
Tab Completion: Start typing and press Tab to auto-complete
Arrow Up/Down: Cycle through previous commands
Control + C: Cancel current command
Control + A: Move cursor to beginning of line
Control + E: Move cursor to end of line
Control + U: Delete everything before cursor
13. Combining Commands
Pipe - Sends output of first command to second
Redirect - Saves output to file
AND - Runs second command only if first succeeds
Useful One-Liners
find ~ -size +1G
du -sh * | sort -rh | head -10
ls -1 | wc -l
curl ifconfig.me
curl -O https://example.com/file.zip
Getting Help
Manual - Shows manual page for command
Press Q to quit manual
Help - Shows command options
rm -rf /- Deletes everything (NEVER run this!):(){ :|:& };:- Fork bomb (crashes system)- Any command from untrusted sources