0% found this document useful (0 votes)
91 views8 pages

Terminal Cheat Sheet

The document provides a cheat sheet of common Mac terminal commands organized by category including navigation, file management, permissions, processes and networking. It lists commands for changing directories, viewing files and folders, copying/moving files, installing software with Homebrew, and searching/outputting information. The cheat sheet serves as a concise reference for many basic and some more advanced terminal commands and their functions on Mac.

Uploaded by

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

Terminal Cheat Sheet

The document provides a cheat sheet of common Mac terminal commands organized by category including navigation, file management, permissions, processes and networking. It lists commands for changing directories, viewing files and folders, copying/moving files, installing software with Homebrew, and searching/outputting information. The cheat sheet serves as a concise reference for many basic and some more advanced terminal commands and their functions on Mac.

Uploaded by

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

The Mac Terminal Commands Cheat Sheet

Cheat Sheet
Command
Shortcuts
Tab
Ctrl + A
Ctrl + E
Ctrl + U
Ctrl + K
Ctrl + W
Ctrl + T
Esc + T
Ctrl + L
Ctrl + C
Ctrl + D
Option + →
Option + ←
Ctrl + F
Ctrl + B
Ctrl + Y
Ctrl + Z
Ctrl + _
Basics
/ (Forward Slash)
. (Single Period)
.. (Double Period)
~ (Tilde)
sudo [command]
nano [file]
open [file]
[command] -h
man [command]
Change Directory
cd
cd [folder]
cd ~
cd/
cd -
pwd
cd..
cd../..
List Directory Contents
ls
ls -C
ls -a
ls -1
ls -F
ls -S
ls -l
ls -lt
ls -lh
ls -lo
ls -la
File Size and Disk Space
du
du -sh [folder]
du -s
du -sk* | sort -nr
df -h
df -H
File and Directory Management
mkdir <dir>
mkdir -p <dir>/<dir>
mkdir <dir1> <dir2> <dir3>
mkdir "<dir>"
rmdir <dir>
rm -R <dir>
touch <file>
cp <file> <dir>
cp <file> <newfile>
cp <file>~/<dir>/<newfile>
cp -R <dir> <"new dir">
cp -i <file><dir>
cp <file1> <file2> <file3>/Users/<dir>
rm <file>
rm -i <file>
rm -f <file>
rm <file1> <file2> <file3>
mv <file> <newfilename>
mv <file> <dir>
mv -i <file> <dir>
mv *.png ~/<dir>
Command History
Ctrl + R
history n
![value]
!!
Permissions
ls -ld
ls -ld/<dir>
chmod 755 <file>
chmod -R 600 <dir>
chown <user>:<group> <file>
Processes
ps -ax
ps -aux
top
top -ocpu -s 5
top -o rsize
kill PID
ps -ax | grep <appname>
Network
ping <host>
whois <domain>
curl -O <url/to/file>
ssh <username>@<host>
scp <file><user>@<host>:/remote/path
Homebrew
brew doctor
brew install <formula>
brew uninstall <formula>
brew list
brew search
brew upgrade
brew update
brew cleanup
brew tap homebrew/cask
brew cask list
brew cask install <cask>
brew cask uninstall <cask>
Search
find <dir> -name <"file">
grep "<text>" <file>
grep -rl "<text>" <dir>
Output
cat <file>
less <file>
head <file>
<cmd> > > <file>
<cmd> > <file>
<cmd1> | <cmd2>
The Mac Terminal Commands Cheat Sheet
Function
Action

Auto-complete file and folder names


Go to the beginning of the line you're currently typing on
Go to the end of the line you're currently typing on
Clear the line before the cursor
Clear the line after the cursor
Delete the word before the cursor
Swap the last two characters before the cursor
Swap the last two words before the cursor
Clear the screen
Kill whatever you're running
Exit the current shell
Move cursor one word forward
Move cursor one word backward
Move cursor one character forward
Move cursor one character backward
Paste whatever was cut by the last command
Puts whatever you're running into a suspended background process
Undo the last command

Top level directory


Current directory
Parent directory
Home directory
Run command with the security privileges of the super user
Opens the Terminal editor
Opens a file
Get help about a command
Show the help manual of the command

Home directory
Change directory, e.g. cd Documents
Home directory
Root of the drive
Previous directory or folder you last browsed
Show your working directory
Move up to the parent directory
Move up two levels
Display the name of files and subdirectories in the directory
Force multi-column output of the listing
List all entries including those with .(period) and ..(double period)
Output the list of files in one entry per line format
Display a / (slash) immediately after each path that is a directory, * (asterisk) after executable programs or scripts, and @ after a symbolic link
Sort files or entries by size
List in a long format. Includes file mode, owner and group name, date and time file was modified, pathname, and more
List the files sorted by time modified (most recent first)
Long listing with human readable file sizes in KB, MB, or GB
List the file names with size, owner, and flags
List detailed directory contents, including hidden files

List usage for each subdirectory and its contents


Human readable output of all files in a directory
Display an entry for each specified file
List files and folders, totaling the size including the subfolders. Replace sk* with sm* to list directories in MB
Calculate your system's free disk space
Calculate free disk space in powers of 1,000 (as opposed to 1,024)

Create new folder named <dir>


Create nested folders
Create several folders at once
Create a folder with a space in the filename
Delete a folder (only works on empty folders)
Delete a folder and its contents
Create a new file without any extension
Copy a file to the folder
Copy a file to the current folder
Copy a file to the folder and rename the copied file
Copy a folder to a new folder with spaces in the filename
Prompts you before copying a file with a warning overwrite message
Copy multiple files to a folder
Delete a file (This deletes the file permanently; use with caution.)
Delete a file only when you give confirmation
Force removal without confirmation
Delete multiple files without any confirmation
Move/rename
Move a file to the folder, possibly by overwriting an existing file
Optional -i flag to warn you before overwriting the file
Move all PNG files from current folder to a different folder
Search through previously used commands
Shows the previous commands you've typed. Add a number to limit to the last n items
Execute the last command typed that starts with a value
Execute the last command typed

Display the default permission for a home directory


Display the read, write, and access permission of a particular folder
Change the permission of a file to 755
Change the permission of a folder (and its contents) to 600
Change the ownership of a file to user and group. Add -R to include folder contents

Output currently running processes. Here, a shows processes from all users and x shows processes that are not connected with the Terminal
Shows all the processes with %cpu, %mem, page in, PID, and command
Display live information about currently running processes
Display processes sorted by CPU usage, updating every 5 seconds
Sort top by memory usage
Quit process with ID <PID>. You'll see PID as a column in the Activity Monitor
Find a process by name or PID

Ping host and display status


Output whois info for a domain
Download file via HTTP, HTTPS, or FTP
Establish SSH connection to <host> with user <username>
Copy <file> to a remote <host>

Check brew for potential problems


Install a formula
Uninstall a formula
List all the installed formulas
Display available formulas for brewing
Upgrade all outdated and unpinned brews
Fetch latest version of homebrew and formula
Remove older version of installed formula
Tap the cask repository from GitHub
List all installed casks
Install the given cask
Uninstall the given cask

Find all files named <file> inside <dir>. Use wildcards (*) to search for parts of filenames
Output all occurrences of <text> inside <file> (add -i for case insensitivity)
Search for all files containing <text> inside <dir>
Output the content of <file>
Output the contents of <file> using the less command that supports pagination and more
Output the first 10 lines of <file>
Appends the output of <cmd> to <file>
Direct the output of <cmd> into <file>
Direct the output of <cmd1> to <cmd2>

You might also like