The Mac Terminal is a powerful tool that allows you to interact with your macOS system using text-based commands. It gives you access to the UNIX shell. You can use it to manage files, directories, networks, and even install software using a command line interface. But you need to learn Mac Terminal commands to effectively use it. Learning Mac terminal commands can provide several key advantages. It lets you perform tasks much faster in some cases. You can perform Batch file operations, system monitoring, and even installing software using Mac terminal commands, It also provides greater control over the system. You can access hidden settings, configure system files, and even modify permissions for files and directories. Some commands can also allow you to automate tasks by creating scripts. You can create scripts to schedule backups, automate file organization, or create scripts to open applications and documents. Some commands also allow you to access advanced features through the terminal.
So, I thought to curate some of the notable Mac terminal commands. In this article, I am adding a wide range of Mac Terminal commands that will help you navigate your Mac more efficiently, automate tasks, and perform advanced system operations.
How to Open Mac Terminal
To open the Terminal on your Mac, follow these steps:
- Press
Command + Space
to open Spotlight. - Type “Terminal” and hit
Enter
.
You can also find the Terminal app in Applications > Utilities > Terminal
.
Basic Terminal Commands
1. pwd (Print Working Directory)
This command prints the current directory you are in.
pwd
2. ls (List Directory Contents)
The ls
command lists all the files and directories in the current directory.
ls
ls -l
: Provides detailed information about each file.ls -a
: Shows hidden files (those starting with a.
).
3. cd (Change Directory)
This command changes the directory you are currently in.
cd [directory_name]
cd ..
: Moves up one directory level.cd ~
: Navigates to your home directory.
4. mkdir (Make Directory)
Use this command to create a new directory.
mkdir [directory_name]
5. rmdir (Remove Directory)
This command removes an empty directory.
rmdir [directory_name]
- For non-empty directories, use the
rm -r
command to remove them.
6. rm (Remove Files)
The rm
command deletes files.
rm [file_name]
rm -r [directory_name]
: Deletes a directory and its contents.- Be cautious: there is no “Undo” option for
rm
.
7. cp (Copy Files)
This command copies files or directories.
cp [source_file] [destination]
cp -r [source_directory] [destination]
: Copies a directory and its contents.
8. mv (Move/Rename Files)
The mv
command moves or renames files or directories.
mv [source_file] [destination]
- If
destination
is a file name, the source file is renamed.
Navigating and Managing Files
9. touch (Create an Empty File)
This command creates a new, empty file.
touch [file_name]
10. cat (Concatenate Files)
The cat
command displays the contents of a file in the terminal.
cat [file_name]
cat [file1] [file2] > [output_file]
: Concatenates files and saves the result in theoutput_file
.
11. head & tail (View Beginning/End of Files)
head [file_name]
: Shows the first 10 lines of a file.tail [file_name]
: Shows the last 10 lines of a file.
You can customize the number of lines displayed using the -n
option:
tail -n 20 [file_name]
12. find (Search for Files)
The find
command searches for files in a directory.
find [directory] -name [file_name]
Example: Find all .txt
files in your home directory:
find ~ -name "*.txt"
13. grep (Search Inside Files)
The grep
command searches for specific text within files.
grep [search_term] [file_name]
grep -r [search_term] [directory]
: Recursively searches for text in all files within a directory.
14. open (Open Files or Applications)
Use the open
command to open files, directories, or applications.
open [file_name]
- To open a directory in Finder:
open [directory_name]
. - To open a specific application:
open -a [Application_Name]
.
15. nano (Text Editor)
nano
is a simple text editor that runs in the terminal.
nano [file_name]
- To exit:
Ctrl + X
.
System Management Commands
16. top (System Monitoring)
The top
command displays a live view of system processes and resource usage.
top
- To exit: Press
q
.
17. ps (Process Status)
The ps
command shows currently running processes for your user.
ps
ps aux
: Displays all system processes.
18. kill (Terminate Processes)
The kill
command terminates a running process using its PID (Process ID).
kill [PID]
- Use
ps
ortop
to find the PID of a process. kill -9 [PID]
: Forces a process to terminate.
19. df (Disk Usage Information)
This command shows disk space usage of all mounted file systems.
df -h
-h
: Shows human-readable format with sizes in KB, MB, or GB.
20. du (Estimate File/Directory Space Usage)
The du
command displays the size of files and directories.
du -sh [directory]
-s
: Summarizes the total space used.-h
: Shows the output in a human-readable format.
21. history (Command History)
The history
command displays the list of previously executed commands.
history
You can repeat a specific command from the history using !
followed by the command number:
!100
22. sudo (Superuser Privileges)
sudo
allows you to execute commands with superuser privileges.
sudo [command]
- Use with caution, as it can modify system-critical files.
23. chmod (Change File Permissions)
This command modifies the permissions of files or directories.
chmod [permissions] [file_name]
Example: Give the owner read, write, and execute permissions:
chmod 755 [file_name]
chmod -R
: Recursively changes permissions for a directory and its contents.
24. chown (Change File Ownership)
The chown
command changes the owner and group of a file or directory.
sudo chown [owner]:[group] [file_name]
Networking Commands
25. ping (Test Network Connectivity)
The ping
command checks the connectivity to a network host.
ping [hostname or IP address]
- To stop: Press
Ctrl + C
.
26. ifconfig (Network Interface Information)
This command displays the status of network interfaces on your Mac.
ifconfig
27. curl (Transfer Data from URLs)
curl
is used to transfer data from or to a server.
curl [URL]
curl -O [URL]
: Downloads a file from the specified URL.
28. ssh (Secure Shell)
The ssh
command connects to a remote server over SSH.
ssh [username]@[host]
Example: Connect to a remote server:
ssh [email protected]
Advanced Commands
29. defaults (Modify macOS Settings)
Use the defaults
command to modify macOS settings.
Example: Change screenshot file format to PNG:
defaults write com.apple.screencapture type png
- To apply the changes, restart the System UI Server:
killall SystemUIServer
30. diskutil (Disk Utility Management)
This command manages and manipulates disks and volumes on macOS.
diskutil list
- To format a disk:
diskutil eraseDisk [file_system] [volume_name] [disk_identifier]
.
Conclusion
Mac Terminal commands can improve your productivity by giving you direct control over your system using a command line interface. Whether you are managing files, monitoring processes, or configuring your system, these commands will help you unlock the full potential of your Mac. There are a few Mac tasks that can only be done using terminal commands. So, it is really important for you to understand and learn Mac terminal commands
Also see:
- List of all macOS versions
- 100+ Mac keyboard shortcuts
- How to Capture Screenshots on Mac
- Linux Commands Cheat Sheet
- AirDrop Not Working? Here’s How to Fix It