
The macOS Terminal is a powerful tool that gives you direct access to the Unix-based core of your Mac. Whether you’re a developer, power user, or just someone looking to streamline tasks, mastering Terminal commands can significantly boost your productivity.
Below is a curated list of useful Terminal commands for macOS, categorized for easy reference.
Networking
Copy table
| Command | Description |
|---|---|
ifconfig | Show network interfaces and IP addresses |
ping [website] | Test network connectivity (e.g., ping google.com) |
curl [URL] | Fetch content from a URL (e.g., curl https://example.com) |
nslookup [domain] | Look up DNS information |
netstat -rn | Display routing table |
lsof -i :[port] | Check which process is using a port (e.g., lsof -i :8080) |
Ping
ping -c (how many pings) ip address
sample
ping -c 4 123.456.789.123

1. Basic Navigation & File Management
Navigating Directories
| Command | Description |
|---|---|
pwd | Print the current working directory |
ls | List files and folders in the current directory |
ls -la | List all files (including hidden ones) in long format |
cd [directory] | Change directory (e.g., cd Documents) |
cd .. | Move up one directory level |
cd ~ or cd | Go to the home directory |
open . | Open the current directory in Finder |

File & Folder Operations
| Command | Description |
|---|---|
mkdir [folder] | Create a new folder (e.g., mkdir Projects) |
touch [file] | Create a new empty file (e.g., touch notes.txt) |
cp [file] [destination] | Copy a file (e.g., cp file.txt ~/Documents/) |
mv [file] [destination] | Move or rename a file (e.g., mv old.txt new.txt) |
rm [file] | Delete a file (e.g., rm temp.txt) |
rm -rf [folder] | Force delete a folder and its contents (⚠️ Dangerous!) |
cat [file] | Display file contents (e.g., cat notes.txt) |
less [file] | View file contents page by page (press q to exit) |
nano [file] | Edit a file in the Nano text editor |
pbcopy < [file] | Copy file contents to clipboard |
pbpaste > [file] | Paste clipboard contents into a file |
2. System Information & Monitoring
Hardware & OS Info
| Command | Description |
|---|---|
uname -a | Display system information (kernel version, etc.) |
sw_vers | Show macOS version details |
system_profiler SPHardwareDataType | Detailed hardware info (CPU, RAM, etc.) |
df -h | Check disk space usage (human-readable format) |
du -sh [folder] | Check folder size (e.g., du -sh ~/Downloads) |
top | View running processes (press q to exit) |
htop | Interactive process viewer (install via brew install htop) |
uptime | Show how long the system has been running |
whoami | Display your current username |
3. File Permissions & Ownership
| Command | Description |
|---|---|
chmod [permissions] [file] | Change file permissions (e.g., chmod 755 script.sh) |
chown [user]:[group] [file] | Change file ownership (e.g., chown user:staff file.txt) |
sudo [command] | Run a command with superuser privileges |
sudo !! | Run the last command with sudo |
Common Permission Codes:
755– Owner: read/write/execute, Group/Others: read/execute644– Owner: read/write, Group/Others: read-only777– Full access (⚠️ Avoid unless necessary!)
4. Package Management (Homebrew)
Homebrew is the best package manager for macOS. Install it first:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Homebrew Commands
| Command | Description |
|---|---|
brew install [package] | Install a package (e.g., brew install wget) |
brew uninstall [package] | Remove a package |
brew update | Update Homebrew itself |
brew upgrade | Upgrade all installed packages |
brew list | List installed packages |
brew search [package] | Search for a package |
brew doctor | Check for issues with Homebrew |
5. Process Management
| Command | Description |
|---|---|
ps aux | List all running processes |
kill [PID] | Terminate a process by ID (e.g., kill 1234) |
killall [process] | Kill all instances of a process (e.g., killall Safari) |
pkill [process] | Kill a process by name |
ctrl + c | Stop the current running command |
ctrl + z | Pause a process (use fg to resume) |
jobs | List background jobs |
bg | Resume a paused job in the background |
fg | Bring a background job to the foreground |
6. Disk & File System Operations
| Command | Description |
|---|---|
diskutil list | List all disks and partitions |
diskutil info [disk] | Get detailed info about a disk (e.g., diskutil info disk0) |
diskutil eraseDisk [format] [name] [disk] | Format a disk (e.g., diskutil eraseDisk APFS "NewDisk" disk2) |
mount | List mounted drives |
umount [disk] | Unmount a disk (e.g., umount /dev/disk2s1) |
dd if=[input] of=[output] | Clone a disk (⚠️ Advanced, use with caution!) |
7. Text & File Manipulation
| Command | Description |
|---|---|
grep "[pattern]" [file] | Search for text in a file (e.g., grep "error" log.txt) |
grep -r "[pattern]" [directory] | Recursively search in a directory |
sed -i '' 's/old/new/g' [file] | Replace text in a file (e.g., sed -i '' 's/foo/bar/g' file.txt) |
awk '{print $1}' [file] | Extract specific columns from a file |
sort [file] | Sort file contents |
uniq [file] | Remove duplicate lines (use with sort first) |
wc -l [file] | Count lines in a file |
diff [file1] [file2] | Compare two files |
tar -xvf [file.tar] | Extract a .tar file |
tar -czvf [archive.tar.gz] [folder] | Compress a folder into .tar.gz |
zip -r [archive.zip] [folder] | Create a ZIP archive |
unzip [file.zip] | Extract a ZIP file |
8. System Maintenance & Optimization
| Command | Description |
|---|---|
sudo softwareupdate -i -a | Install all available macOS updates |
sudo purge | Clear inactive memory (macOS 10.13 and earlier) |
sudo mdutil -E / | Rebuild Spotlight index |
sudo rm -rf /private/var/log/* | Clear system logs (⚠️ Be careful!) |
sudo rm -rf ~/Library/Caches/* | Clear user cache |
defaults write com.apple.finder AppleShowAllFiles YES | Show hidden files in Finder |
defaults write com.apple.finder AppleShowAllFiles NO | Hide hidden files |
sudo shutdown -r now | Reboot immediately |
sudo shutdown -h now | Shut down immediately |
9. Fun & Useful One-Liners
| Command | Description |
|---|---|
say "Hello" | Make your Mac speak |
caffeinate -t 3600 | Prevent Mac from sleeping for 1 hour |
open -a "App Name" | Open an app (e.g., open -a "Safari") |
screencapture -i screenshot.png | Take an interactive screenshot |
networksetup -setairportpower en0 off | Turn off Wi-Fi |
networksetup -setairportpower en0 on | Turn on Wi-Fi |
curl -s https://icanhazdadjoke.com | Get a random dad joke |
fortune | Display a random quote (install via brew install fortune) |
10. Customizing the Terminal
Change Terminal Appearance
| Command | Description |
|---|---|
export PS1="\u@\h \W $ " | Customize the prompt (e.g., user@MacBook ~ $) |
alias ll='ls -la' | Create a shortcut for ls -la |
nano ~/.zshrc | Edit Zsh configuration (macOS default shell) |
source ~/.zshrc | Reload Zsh config after changes |
Install Oh My Zsh (Better Terminal Experience)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Final Tips
✅ Use Tab for auto-completion – Saves time when typing file paths.
✅ Use ↑ and ↓ arrows – Navigate command history.
✅ Use ctrl + r – Search through command history.
✅ Use man [command] – View the manual for any command (e.g., man ls).
✅ Be careful with sudo and rm -rf – These can cause irreversible damage if misused.
Conclusion
The macOS Terminal is a powerful tool that can help you automate tasks, manage files, monitor system performance, and much more. While it may seem intimidating at first, mastering these commands will make you a more efficient Mac user.
Start with the basics, experiment in a safe environment, and gradually explore more advanced commands. Happy terminal-ing! 🚀
Mac OS Ping info
You can use the ping command to verify the connectivity between two network devices that are IP (Internet Protocol) based.
To ping a network device using a system that is running OSX, complete the following:
- Click Applications > Utilities > Terminal.
- Type ping -c <number of times to ping> <IP address>. The IP address is xxx.xxx.xxx.xxx, where xxx is a number between 0 and 255. For example, to ping 192.168.1.1 five times, you would type ping -c 5 192.168.1.1.
Note: If you do not enter the number of times that you want to ping the IP address, your system will continuously ping the address until you manually stop it. To stop pinging the IP address, press Control + C.
If the ping is successful, you should receive replies from the address that you are trying to ping. If the ping is unsuccessful, you need to diagnose your network setup further.
To verify if your local network adapter is working, you can ping 127.0.0.1, which is a loopback address. The loopback address is a virtual network port for most operating systems.
