The 20 Mac Terminal Commands is a powerful tool that gives you direct access to the core of your Mac’s operating system. While it might seem intimidating at first, mastering these essential commands can significantly enhance your productivity and give you greater control over your machine.
The Terminal app on macOS is more than just a black screen with blinking text—it’s a gateway to powerful functionality that often surpasses what’s possible through the graphical interface. This guide will walk you through 20 must-know Terminal commands that will help you navigate, manipulate files, and manage your system more effectively.
Essential Navigation and File Management
1. Change Directory (cd)
The cd
command is your primary tool for navigation in Terminal.
cd /path/to/directory # Navigate to specific directory
cd .. # Move up one directory
cd ~ # Go to home directory
2. Listing Directory Contents (ls)
View the contents of your current directory with various options:
ls # Basic directory listing
ls -l # Detailed listing with permissions and sizes
ls -a # Show hidden files
ls -lah # Detailed listing including hidden files, with human-readable sizes
3. Opening Files (open)
The open
command is versatile and works with files and applications:
open file.txt # Opens with default application
open -a "App Name" file # Opens with specified application
open . # Opens current directory in Finder
4. Copying Files (cp)
Copy files and directories with preservation of attributes:
cp source.txt destination.txt
cp -R sourcefolder/ destinationfolder/ # Copy directories recursively
5. Moving Files (mv)
Move or rename files and directories:
mv oldname.txt newname.txt # Rename file
mv file.txt /path/to/newlocation/ # Move file
File and Directory Creation/Deletion
6. Creating Text Files (touch)
Create empty files or update timestamps:
touch newfile.txt
touch -t 202402171200 file.txt # Set specific timestamp
7. Creating Directories (mkdir)
Make new directories with optional parent directories:
mkdir newdirectory
mkdir -p parent/child/grandchild # Create nested directories
8. Removing Empty Directories (rmdir)
Safely remove empty directories:
rmdir emptyfolder
9. Removing Nested Directories (rm)
Remove directories and their contents (use with caution):
rm -rf directory # Force remove directory and contents
System Management and Administration
10. Superuser Privileges (sudo)
Execute commands with administrative privileges:
sudo command # Prompts for password
sudo -s # Start a root shell session
11. Process Management (ps)
View running processes:
ps aux # Show all processes
ps aux | grep "process-name" # Search for specific process
12. Exiting Sub-screens (Control + D)
When in a sub-screen or shell:
Control + D # Exit current shell/screen
13. Clear Screen (clear)
Clean up your Terminal view:
clear # Clear screen
Command + K # Alternative clear method
Advanced Operations
14. Directory Content Copying (ditto)
Preserve file attributes while copying:
ditto source_folder destination_folder
15. Command Help (whatis)
Get quick command descriptions:
whatis command # Shows one-line description
16. Manual Pages (man)
Access detailed command documentation:
man command # Shows full manual page
17. Exit Terminal (exit)
Properly close Terminal sessions:
exit # Close current session
System-Specific Operations
18. Running Shortcuts
Execute Shortcuts from Terminal:
shortcuts run "Shortcut Name"
19. Time Machine Operations
Manage backups via Terminal:
tmutil startbackup # Start backup
tmutil listbackups # List available backups
20. Force Quit Applications
Force quit unresponsive applications:
killall "Application Name"
Conclusion
These Terminal commands form the foundation for efficient Mac system management. While the graphical interface is user-friendly, mastering these commands gives you more precise control and can often help you accomplish tasks more quickly. Remember to always exercise caution with powerful commands, especially those involving deletion or system modifications.
Pro Tips
- Create aliases for frequently used commands in your
.zshrc
or.bash_profile
- Use Tab completion to avoid typing full paths
- Keep a cheat sheet handy until these commands become second nature
- Always double-check destructive commands before executing them
- Use
--help
or-h
flags when unsure about command options