The macOS Terminal provides a command-line interface that can greatly enhance productivity for developers. Understanding and utilizing the right terminal commands can simplify complex tasks and automate repetitive ones. This cheat sheet covers the most common and useful terminal commands that developers typically use in the macOS environment.
Navigating the file system
Command | Description |
---|
pwd | Print the current directory path. |
ls | List all files and directories in the current directory. |
ls -a | List all entries including hidden files. |
ls -l | List with long format - show permissions, owner, size, and modification date. |
cd directory_name | Change directory to directory_name . |
cd .. | Go up one directory level. |
cd ~ or cd | Go to the home directory. |
mkdir directory_name | Create a new directory named directory_name . |
rmdir directory_name | Delete an empty directory named directory_name . |
rm file_name | Delete a file named file_name . |
rm -r directory_name | Recursively delete a directory and its contents. |
cp file1 file2 | Copy file1 to file2 . |
cp -r dir1 dir2 | Copy directory dir1 to dir2 ; create dir2 if it doesn't exist. |
mv old_name new_name | Rename or move a file/directory from old_name to new_name . |
Working with files
Command | Description |
---|
touch file_name | Create a new file or update the timestamp of file_name . |
cat file_name | Display the content of file_name . |
more file_name | Display the content of file_name one screen at a time. |
less file_name | An improved version of more , with backward navigation. |
open file_name | Open file_name with the default associated application. |
nano file_name | Open file_name in the nano editor, installed by default. |
vi file_name | Open file_name in the Vi editor. |
System monitoring and management
Command | Description |
---|
top | Display active processes and system stats. |
htop (if installed) | An interactive process viewer (not installed by default). |
ps aux | Show detailed status of all current processes. |
kill pid | Kill a process with process ID pid . |
killall process_name | Kill all processes named process_name . |
df | Display disk space usage. |
du | Show the disk usage of the files and directories in the current directory. |
Network utilities
Command | Description |
---|
ping host | Check the network connection to host . |
curl url | Download the file from url . |
wget url | Download the file from url (if installed). |
ssh user@host | Connect to host as user via SSH. |
scp file user@host:path | Securely copy file to host under path . |
ftp host | Connect to host using FTP. |
File permissions
Command | Description |
---|
chmod permissions file_name | Change the permissions of file_name to permissions (e.g., chmod 755 file_name ). |
chown user file_name | Change the owner of file_name to user . |
chgrp group file_name | Change the group of file_name to group . |
Miscellaneous
Command | Description |
---|
man command | Display the manual for command . |
echo "text" | Print text to the terminal. |
date | Show the current date and time. |
cal | Show the month's calendar. |
uptime | Show how long the system has been running. |
alias new='commands' | Create an alias new that executes commands . |
This cheat sheet should serve as a quick reference for macOS terminal commands, helping developers to navigate and utilize their Mac systems more effectively. Whether you're a beginner looking to learn the basics or an experienced developer needing a quick refresher, these commands are essential for your daily development tasks.