The Mac Terminal is a powerful command-line interface that gives you direct control over your macOS system, allowing you to perform advanced tasks that aren’t possible through the graphical interface. This comprehensive cheat sheet provides essential Mac Terminal commands organized by category, complete with examples and keyboard shortcuts to help beginners master the command line efficiently.
Getting Started with Mac Terminal Commands
Opening Terminal
The easiest way to open Terminal is by pressing Command + Space to launch Spotlight, then typing “Terminal” and pressing Enter. Alternatively, navigate to Applications > Utilities > Terminal. geeksforgeeks
Essential Keyboard Shortcuts for Mac Terminal Commands
Before diving into commands, familiarize yourself with these productivity-boosting shortcuts: apple
| Shortcut | Description |
|---|---|
| Command + T | Open a new Terminal tab |
| Command + N | Open a new Terminal window |
| Command + W | Close current tab or window |
| Control + C | Cancel the current command |
| Control + D | Exit current session |
| Control + A | Move cursor to beginning of line |
| Control + E | Move cursor to end of line |
| Control + U | Delete everything before cursor |
| Control + K | Delete everything after cursor |
| Control + L | Clear the screen |
| Tab | Auto-complete file/directory names |
| Up Arrow | Recall previous commands |
Navigation Commands for Mac Terminal Commands
Master these fundamental navigation commands to move efficiently through your file system: graphite
| Command | Description | Example |
|---|---|---|
pwd |
Print current working directory | pwd |
cd |
Go to home directory | cd |
cd [folder] |
Change to specific directory | cd Documents |
cd .. |
Move up one directory level | cd .. |
cd ../.. |
Move up two directory levels | cd ../.. |
cd ~ |
Go to home directory | cd ~ |
cd / |
Go to root directory | cd / |
cd - |
Return to previous directory | cd - |
Listing Directory Contents
View and examine files and folders in your current location: phoenixnap
| Command | Description | Example |
|---|---|---|
ls |
List files and directories | ls |
ls -l |
Long format with permissions and details | ls -l |
ls -a |
Show all files including hidden ones | ls -a |
ls -la |
Combined long format with hidden files | ls -la |
ls -lh |
Human-readable file sizes | ls -lh |
ls -S |
Sort by file size | ls -S |
ls -t |
Sort by modification time | ls -t |
File and Directory Management
Essential commands for creating new files and folders:
| Command | Description | Example |
|---|---|---|
touch [file] |
Create empty file | touch newfile.txt |
mkdir [directory] |
Create new directory | mkdir Projects |
mkdir -p [path] |
Create nested directories | mkdir -p Work/2024/Reports |
Copying and Moving Files
Manage your files efficiently with these copy and move operations:
| Command | Description | Example |
|---|---|---|
cp [file] [destination] |
Copy file to destination | cp file.txt /Documents/ |
cp -r [dir] [destination] |
Copy directory recursively | cp -r folder1 folder2 |
mv [source] [destination] |
Move or rename files/directories | mv oldname.txt newname.txt |
mv [file] [directory] |
Move file to directory | mv file.txt /Documents/ |
Deleting Files and Directories
Remove files and directories safely:
| Command | Description | Example |
|---|---|---|
rm [file] |
Delete file | rm unwanted.txt |
rm -i [file] |
Delete with confirmation prompt | rm -i file.txt |
rm -r [directory] |
Delete directory and contents | rm -r old_folder |
rm -rf [directory] |
Force delete without prompts | rm -rf temp_folder |
rmdir [directory] |
Delete empty directory | rmdir empty_folder |
File Content Operations
Read and examine file contents without opening external applications:
| Command | Description | Example |
|---|---|---|
cat [file] |
Display entire file content | cat readme.txt |
less [file] |
View file with pagination | less longfile.txt |
head [file] |
Show first 10 lines | head logfile.txt |
head -n 5 [file] |
Show first 5 lines | head -n 5 file.txt |
tail [file] |
Show last 10 lines | tail logfile.txt |
tail -f [file] |
Follow file updates in real-time | tail -f system.log |
Text Editing
Basic text editing capabilities directly in Terminal:
| Command | Description | Example |
|---|---|---|
nano [file] |
Edit file with Nano editor | nano config.txt |
open [file] |
Open file with default application | open document.pdf |
System Monitoring and Process Management
Monitor system performance and running applications:
| Command | Description | Example |
|---|---|---|
top |
Display running processes dynamically | top |
ps aux |
Show detailed process information | ps aux |
ps -ax |
List all running processes | ps -ax |
kill [PID] |
Terminate process by ID | kill 1234 |
killall [process] |
Kill all processes by name | killall Safari |
System Information
Gather information about your Mac system:
| Command | Description | Example |
|---|---|---|
system_profiler SPHardwareDataType |
Display hardware information | system_profiler SPHardwareDataType |
uptime |
Show system uptime | uptime |
date |
Display current date and time | date |
cal |
Show calendar | cal |
whoami |
Display current username | whoami |
Disk and Storage Management
Monitor and manage storage space effectively:
| Command | Description | Example |
|---|---|---|
df -h |
Show disk space in human-readable format | df -h |
du -sh [directory] |
Show directory size | du -sh Documents/ |
du -h |
Display disk usage for all files | du -h |
diskutil list |
List all drives and partitions | diskutil list |
Network and Connectivity
Test connectivity and manage network operations:
| Command | Description | Example |
|---|---|---|
ping [host] |
Test network connectivity | ping google.com |
curl [URL] |
Download files from web | curl -O http://example.com/file.zip |
ssh [user@host] |
Connect to remote server | ssh user@192.168.1.1 |
scp [file] [user@host:path] |
Secure copy to remote server | scp file.txt user@server:/home/ |
ifconfig |
Display network interface information | ifconfig en0 |
Search and Find Operations
Locate files and content efficiently across your system:
| Command | Description | Example |
|---|---|---|
find [path] -name [pattern] |
Search for files by name | find /Users -name "*.txt" |
find [path] -size +[size] |
Find files larger than size | find /Downloads -size +10M |
grep "[text]" [file] |
Search for text in files | grep "error" logfile.txt |
grep -r "[text]" [directory] |
Recursive text search | grep -r "TODO" /Projects/ |
File Permissions and Ownership
Control file access and security settings:
| Command | Description | Example |
|---|---|---|
ls -l |
View file permissions | ls -l myfile.txt |
chmod 755 [file] |
Set file permissions | chmod 755 script.sh |
chmod +x [file] |
Make file executable | chmod +x myscript.sh |
chown [user] [file] |
Change file owner | chown john file.txt |
sudo [command] |
Execute command with admin privileges | sudo rm /System/file |
Command History and Help
Access and reuse previous commands efficiently:
| Command | Description | Example |
|---|---|---|
history |
Show command history | history |
history 10 |
Show last 10 commands | history 10 |
!! |
Repeat last command | !! |
![number] |
Execute command by history number | !1009 |
Control + R |
Search command history interactively | Press Ctrl+R and type |
Getting Help
Access documentation and command assistance:
| Command | Description | Example |
|---|---|---|
man [command] |
Display manual page | man ls |
[command] --help |
Show command help | mkdir --help |
whatis [command] |
Brief command description | whatis grep |
Advanced Tips for Beginners
Combine multiple commands for powerful workflows:
| Operator | Description | Example |
|---|---|---|
&& |
Execute next command if first succeeds | mkdir test && cd test |
| ` | ` | |
; |
Execute commands sequentially | ls; pwd; date |
| ` | ` | Pipe output to next command |
Output Redirection
Control where command output goes:
| Operator | Description | Example |
|---|---|---|
> |
Redirect output to file (overwrite) | ls > filelist.txt |
>> |
Append output to file | echo "new line" >> file.txt |
< |
Use file as input | sort < unsorted.txt |
Best Practices for Beginners
Safety and Efficiency Tips:
-
Always double-check destructive commands like
rm -rfbefore pressing Enter -
Use tab completion to avoid typos and speed up typing
-
Start with
lsto see current directory contents before performing operations -
Practice in a test directory first when learning new commands
-
Use the
-iflag with delete and overwrite operations for confirmation prompts
Common Beginner Mistakes to Avoid:
-
Running
sudocommands without understanding their impact -
Using
rm -rfwithout verifying the path -
Forgetting that macOS file paths are case-sensitive
-
Not backing up important files before testing commands
Conclusion
Mastering Mac Terminal commands significantly enhances your productivity and gives you powerful control over your macOS system. Start with basic navigation and file management commands, then gradually incorporate more advanced features like process monitoring, network utilities, and command chaining. Regular practice with these essential commands will transform you from a Terminal beginner into a confident command-line user capable of automating tasks and troubleshooting system issues effectively.
Remember that the Terminal is a powerful tool—always exercise caution with system-level commands and maintain backups of important data. With consistent practice using this cheat sheet, you’ll soon find the command line faster and more efficient than traditional graphical interfaces for many tasks.

