0% found this document useful (0 votes)
17 views10 pages

Complete Mac Terminal Commands Cheat Sheet

The document is a comprehensive cheat sheet for Mac Terminal commands, designed to enhance user productivity by providing essential commands for file management, networking, system diagnostics, and more. It includes keyboard shortcuts, command descriptions, and examples for both beginners and advanced users. The guide aims to simplify the use of Terminal for various tasks, from basic navigation to advanced system operations.

Uploaded by

kizzlah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Complete Mac Terminal Commands Cheat Sheet

The document is a comprehensive cheat sheet for Mac Terminal commands, designed to enhance user productivity by providing essential commands for file management, networking, system diagnostics, and more. It includes keyboard shortcuts, command descriptions, and examples for both beginners and advanced users. The guide aims to simplify the use of Terminal for various tasks, from basic navigation to advanced system operations.

Uploaded by

kizzlah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

www.geeksforgeeks.

org /complete-mac-terminal-commands-cheat-sheet/

Complete Mac Terminal Commands Cheat Sheet


GeeksforGeeks ⋮ 15-19 minutes ⋮ 8/20/2020

Last Updated : 09 Dec, 2024

The Mac Terminal is a powerful tool that allows you to interact with your macOS system
through commands, giving you more control over your device than ever before. Whether
you’re a beginner exploring basic commands or an advanced user looking to
streamline tasks, mastering Mac Terminal commands can significantly increase your
productivity. From managing files and directories to troubleshooting your system or
customizing settings, the Terminal opens up a world of possibilities beyond the standard
macOS interface.

Have you ever searched for ways to navigate macOS faster, fix errors, or
automate tasks? Knowing the right Terminal commands can help you
perform these actions efficiently.

In this comprehensive Mac Terminal commands cheat sheet, we’ve compiled


essential commands for file management, networking, system diagnostics, and
more, tailored to meet your needs. Whether you’re an IT professional, developer, or casual
user, this cheat sheet will make using the Terminal simpler and more effective.

Shortcuts Key For Mac Terminal


Before moving toward the Mac Terminal commands, let’s know some shortcut keys to
access the Mac Terminal. These key combinations help you to increase your work
efficiency.

Mac Terminal Keyboard Shortcuts

Shortcut Description
Command + T Open a new Terminal tab.
Command + N Open a new Terminal window.
Command + W Close the current Terminal tab or window.
Control + C Cancel the current command or process.
Control + D Exit the current session or close the Terminal window.
Control + Z Pause the current process and send it to the background.
Command + K Clear the Terminal screen.
Shortcut Description
Control + L Clear the screen (similar to Command + K).
Command + Arrow Up Scroll up through previous commands in the history.
Command + Arrow
Scroll down through the command history.
Down
Control + A Move the cursor to the beginning of the line.
Control + E Move the cursor to the end of the line.
Control + U Delete everything from the cursor to the beginning of the line.
Control + K Delete everything from the cursor to the end of the line.
Control + W Delete the word before the cursor.
Control + Y Paste the last deleted text.
Control + R Search the command history.
Resume a paused process (if it was paused using Control +
Control + S
Z).
Control + C Interrupt a running process.
Option + Left Arrow Move the cursor one word left.
Option + Right
Move the cursor one word right.
Arrow
Command + Shift + G Go to a specific directory by entering its path.
Tab Auto-complete file or directory name.

Complete Mac Terminal Commands


In this section, you will get a complete table for Mac Terminal commands, we will start
with the basics Mac terminal commands to advance Mac terminal commands like
“Network, Homebrew, Environment Variable or Path, and more.”

Basics Mac Terminal Commands

Command Description Example


/ (Forward Represents the root directory in the file
/
Slash) system.
. (Single Refers to the current directory in which
.
Period) you’re working.
.. (Double Refers to the parent directory (one level up
..
Period) from the current directory).
Represents the home directory of the current
~ (Tilde) ~
user.
Command Description Example
sudo Executes a command with elevated (super sudo rm -rf /path/
[command] user) privileges. to/folder
Opens the Nano text editor to create or edit
nano [file] nano myfile.txt
a file directly in the terminal.
Opens a specified file with the default
open [file] open myfile.txt
application associated with its type.

Mac Terminal Command for Change Directory

Command Description Example


cd Navigate to the home directory cd
cd Change to a specific directory (e.g., Documents, cd
[folder] Downloads) Documents
Go to the home directory (shortcut for the user’s home
cd ~ cd ~
directory)
cd / Navigate to the root directory of the file system cd /
cd - Go back to the previous directory you were last working in cd -
pwd Print the current working directory pwd
cd.. Move up one level to the parent directory cd..
cd../.. Move up two levels in the directory structure cd../..

List Directory Contents Commands

Command Description Example


ls Lists all files and subdirectories in the current directory. ls
ls -C Displays the contents of the directory in a multi-column format. ls -C
Shows all entries in the directory, including hidden files (those
ls -a ls -a
starting with a period).
ls -1 Lists files and directories, one entry per line. ls -1
Adds special symbols: a / after directories, a * after executable
ls -F ls -F
files, and an @ after symlinks.
ls -S Sorts files and directories by size, with the largest listed first. ls -S
Lists files in long format, including file permissions, owner, group,
ls -l ls -l
size, and modification date.
Displays a detailed list of files starting from the root directory,
ls -l / ls -l /
including symbolic links.
Lists files in long format, sorted by modification time (newest
ls -lt ls -lt
first).
Command Description Example
Displays file sizes in human-readable format (KB, MB, GB, etc.)
ls -lh ls -lh
along with other detailed information.
Lists files with detailed information, including file size, owner, and
ls -lo ls -lo
flags.
Shows a detailed list of all files, including hidden files (those
ls -la ls -la
starting with a period).

Mac Terminal Commands for File Size and Disk Space

Command Description Example


Displays the disk usage of each
du du
subdirectory and its contents
Shows a human-readable output of
du -sh
the total size of all files in a specified du -sh /Documents
[folder]
directory
Shows the total disk usage for the
du -s du -s /Users/YourUsername
specified files or directories
Lists all files and folders with their
`du -sk* sort -nr` sizes, including subfolders, sorted by
size
Displays the available free disk space
df -h on your system in a human-readable df -h
format
Displays the free disk space in
df -H df -H
powers of 1,000 instead of 1,024

File and Directory Management Commands

Command Description Example


Creates a new directory
mkdir <dir> mkdir Projects
with the specified name.
mkdir -p <dir>/ Creates nested directories mkdir -p Work/2023/
<dir> in a single command. Reports
mkdir <dir1> <dir2> Creates multiple directories mkdir Folder1 Folder2
<dir3> at once. Folder3
Creates a folder with spaces
mkdir "<dir>" mkdir "My New Folder"
in its name.
rmdir <dir> Deletes an empty directory. rmdir OldFolder
Command Description Example
Removes a directory and all
rm -R <dir> rm -R ProjectFolder
of its contents.
Creates a new, empty file
touch <file> touch newfile.txt
without any extension.
Copies a file to a specified
cp <file> <dir> cp file.txt /Documents/
directory.
Copies a file to the current
cp <file> <newfile> cp file.txt newfile.txt
directory and renames it.
Copies a file to a specified cp report.txt ~/
cp <file>~/<dir>/
folder and renames it Documents/Reports/
<newfile>
during the process. summary.txt
Copies an entire directory,
cp -R <dir> <"new cp -R folder1 "New
including its contents, to a
dir"> Folder"
new location.
Prompts you for
confirmation before
cp -i <file><dir> cp -i file1.txt /Backup/
overwriting a file during
copy.
cp file1.txt file2.txt /
cp <file1> <file2> Copies multiple files into a
Users/username/
<file3>/Users/<dir> directory.
Documents/
Copies the contents of one
ditto -V [folder ditto -V /Folder1 /
folder to another, with
path][new folder] Folder2
status updates.
Deletes a specified file
rm <file> rm unwantedfile.txt
permanently.
Deletes a file with a prompt
rm -i <file> rm -i oldfile.txt
for confirmation.
Forces the deletion of a file
rm -f <file> rm -f tempfile.txt
without any confirmation.
rm <file1> <file2> Deletes multiple files at rm file1.txt file2.txt
<file3> once without confirmation. file3.txt
mv <file> Moves or renames a file to a mv oldfile.txt
<newfilename> new location or name. newfile.txt
Moves a file to a different mv file.txt /Documents/
mv <file> <dir>
directory. Backup/
Moves a file to a folder and
mv -i file1.txt /
mv -i <file> <dir> asks for confirmation before
Documents/Backup/
overwriting.
Command Description Example
Moves all PNG files from
mv *.png ~/<dir> the current directory to mv *.png ~/Pictures/
another directory.

Mac Command History

Command Description Example


history Shows the last n commands you’ve typed, allowing you to quickly history
n review previous commands. 5
Executes the last command that starts with the given string or
![value] !ls
value.
Runs the last command typed, saving you from having to retype
!! !!
it.

Mac Terminal Permissions Commands

Command Description Example


Displays the default permissions for a
ls -ld ls -ld ~
directory, such as a home directory.
Shows the read, write, and access ls -ld /
ls -ld <dir>
permissions of a specific directory or folder. Documents/Work
Modifies the permissions of a file, setting it
chmod 755
chmod 755 <file> to read, write, and execute for the owner,
myscript.sh
and read and execute for others.
Changes the permissions of a directory (and
chmod -R 600 chmod -R 600 /
its contents) to read and write for the owner
<dir> Projects/
only, with no permissions for others.
chown Changes the ownership of a file or directory chown
<user>:<group> to a specified user and group. Add -R to user:admin
<file> apply this to all files within a folder. myfile.txt

Mac Network Commands for Terminal

Command Description Example


Sends a network request to the
specified host to check
ping <host> ping google.com
connectivity and displays the
response time.
whois <domain> Retrieves and displays whois example.com
information about the
Command Description Example
registered domain, including
ownership and registration
details.
Downloads a file from the
curl -O <url/to/ curl -O http://
specified URL using HTTP,
file> example.com/file.zip
HTTPS, or FTP protocols.
Connects to a remote system
ssh securely via SSH (Secure
ssh user@192.168.1.1
<username>@<host> Shell) using the provided
username and host.
scp <file> Copies a local file to a remote scp file.txt
<user>@<host>:/ host using SCP (Secure Copy user@192.168.1.1:/
remote/path Protocol). home/user/
Displays a list of all devices
currently on your local
arp -a arp -a
network, showing their IP and
MAC addresses.
Displays the network
configuration details,
ifconfig en0 ifconfig en0
including the IP and MAC
address of your device.
Traces the route taken by data
traceroute packets from your system to a traceroute
[hostname] destination address, showing example.com
each hop along the way.

Processes Commands

Command Description Example


Displays a list of all currently running processes, including
ps -ax ps -ax
those from other users and background tasks.
Lists detailed information about running processes,
ps -aux including CPU usage, memory usage, PID, and the ps -aux
command being run.
Provides real-time information on running processes,
top top
displaying CPU and memory usage dynamically.
top -ocpu - Displays processes sorted by CPU usage, updating every 5 top -ocpu
s 5 seconds. -s 5
top -o Sorts the top command output by memory usage (resident top -o
rsize memory size). rsize
Command Description Example
Terminates the process identified by its process ID (PID),
kill PID kill 12345
which can be found in ps or top output.

Homebrew Commands

Command Description Example


Check your Homebrew installation
brew doctor brew doctor
for potential issues.
Display a list of useful Homebrew
brew help brew help
formula and cask commands.
List only the installed formulae brew list --
brew list --formula
(packages). formula
List only the installed casks (GUI brew list --
brew list --cask
applications). cask
List only outdated formulas brew outdated
brew outdated --formula
(packages). --formula
List only outdated casks (GUI brew outdated
brew outdated --cask
applications). --cask
brew pin Pin a formula or cask to prevent it brew pin
[installed_formula] from being upgraded automatically. python
brew unpin Unpin a formula or cask to allow it to brew unpin
[installed_formula] be upgraded again. python
Clean up stale lock files, outdated
brew cleanup brew cleanup
versions, and unnecessary files.

Environment Variable or Path

Command Description Example


Lists the current environment variables
printenv printenv
and shows information about your shell.
Prints a message or value to the $echo "Hello,
$echo
Terminal. World!"
Displays the directories listed in the
echo $PATH PATH variable, which are used to locate echo $PATH
executable files.
echo $PATH > Saves the current PATH variable content echo $PATH >
path.txt to a text file. path.txt
export Adds a new directory to the current export
PATH=$PATH:/new/ PATH for the session, allowing you to PATH=$PATH:/usr/
Command Description Example
path run programs from there. local/bin

Search Commands for Mac Terminal

Command Description Example


Search for all files named <file> within the
find <dir> - find /Users/ -
specified directory <dir>. Use wildcards (*) to
name <"file"> name "*.txt"
match partial filenames.
find <dir> - Find files larger than a specified size in the find /Documents
size +<size> given directory <dir>. -size +10M
find <dir> - Find files smaller than a specified size in the find /Downloads
size -<size> given directory <dir>. -size -5M
Search for and display all occurrences of
grep "<text>" grep "error"
<text> within a file <file>. Use -i to make
<file> logfile.txt
the search case-insensitive.
grep -rl Recursively search for files within a directory grep -rl "TODO"
"<text>" <dir> <dir> that contain the specified <text>. /Projects/

Output Commands

Command Description Example


Displays the entire content of the
cat <file> specified file directly in the cat myfile.txt
Terminal.
Displays the content of a file in a
less
paginated view, allowing for easy less myfile.txt
<file>
scrolling.
head
Displays the first 10 lines of a file. head myfile.txt
<file>
<cmd> < Uses the content of a file as input
sort < file.txt
file for a command.
<cmd> >> Appends the output of a
echo "New text" >> myfile.txt
<file> command to the specified file.
Redirects the output of a
<cmd> >
command into the specified file, ls > directory_list.txt
<file>
overwriting it.
Sends the output of one command as
`<cmd1> <cmd2>`
input to another command (pipe).

HELP Commands
Command Description Example
[command] -h Displays basic help information about a command ls -h
[command] -- mkdir --
Provides detailed help and options for a command
help help
[command] help Displays help for the specified command cp help
reset Resets the Terminal display to its default state reset
Shows the manual page for a given command, with
man [command] man ls
details
whatis
Provides a brief, one-line description of a command whatis ls
[command]

Conclusion
It is a bit hard to learn all the Mac Terminal commands mentioned above, but once you get
used to it, it will help you control your system more easily. It might seem tricky at first, but
once you learn the basic commands, it can make your work faster and more efficient. With
the commands and shortcuts in this guide, you’ll be able to navigate macOS, fix problems,
and automate tasks like a pro.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy