Terminal Cheat Sheet
Terminal 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
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
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
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>