MacOS Terminal Cheat Sheet

Tested on macOS mojave

When I first switched from windows from macOSX; I faced some difficulties with the terminal and overall keyboard shortcuts (i.e. quick screen-shot). So I compiled this list from the mighty internet

Frequent keyboard shortcuts Link to heading

Key/CommandDescription
cmd + shift + .Hide / Un-hide file
hold option while clickShow extra context menu
option + cmd + deleteDelete files permanently
cmd + shift + 3Take Screenshot
ctrl + spaceChange keyboard layout
f11Show desktop
cmd + option + vCut while Pasting
cmd + QClose application
cmd + WClose tab
cmd + tabMove focus to next application
ctrl + tabMove focus to next tab
cmd + shift + ↑/↓Select a whole document from the cursor position in a desired direction
cmd + shift + ←/→Select a line to the left or right
alt + shift + ←/→Select a word left or right from the cursor position
cmd + ,Open preferences of active application
cmd + tapChrome: open in new tab
shift + cmd + tapChrome: open in new tab & bring to front
cmd + BJetbrains: Goto declaration
  • If you want to close a bunch of applications at once, press Cmd+Tab to bring up the application switcher. Keep holding Cmd, then use the arrow keys to select different applications, pressing “Q” to instantly close the currently selected application. Keep doing this, holding Cmd, until all the apps you want closed are gone.

SHORTCUTS Link to heading

Key/CommandDescription
Ctrl + AGo to the beginning of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
Ctrl + EGo to the end of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
Ctrl + CClears everything on current line
Ctrl + LClears the Screen
Cmd + KClears the Screen
Ctrl + UCut everything backwards to beginning of line
Ctrl + KCut everything forward to end of line
Ctrl + WCut one word backwards using white space as delimiter
Ctrl + YPaste whatever was cut by the last cut command
Ctrl + HSame as backspace
Ctrl + CKill whatever you are running
Ctrl + DExit the current shell when no process is running, or send EOF to a the running process
Ctrl + ZPuts whatever you are running into a suspended background process. fg restores it.
Ctrl + _Undo the last command. (Underscore. So it’s actually Ctrl + Shift + minus)
Ctrl + TSwap the last two characters before the cursor
Ctrl + FMove cursor one character forward
Ctrl + BMove cursor one character backward
Option + →Move cursor one word forward
Option + ←Move cursor one word backward
Esc + TSwap the last two words before the cursor
TabAuto-complete files and folder names

CORE COMMANDS Link to heading

Key/CommandDescription
cd [folder]Change directory e.g. cd Documents
cdHome directory
cd ~Home directory
cd /Root of drive
cd -Previous directory
lsShort listing
ls -lLong listing
ls -aListing incl. hidden files
ls -lhLong listing with Human readable file sizes
ls -REntire content of folder recursively
sudo [command]Run command with the security privileges of the superuser (Super User DO)
open [file]Opens a file ( as if you double clicked it )
topDisplays active processes. Press q to quit
nano [file]Opens the file using the nano editor
vim [file]Opens the file using the vim editor
clearClears the screen
resetResets the terminal display

CHAINING COMMANDS Link to heading

Key/CommandDescription
[command-a]; [command-b]Run command A and then B, regardless of success of A
[command-a] && [command-b]Run command B if A succeeded
[command-a] || [command-b]Run command B if A failed
[command-a] &Run command A in background

PIPING COMMANDS Link to heading

Key/CommandDescription
[command-a] | [command-b]Run command A and then pass the result to command B e.g ps auxwww | grep google

COMMAND HISTORY Link to heading

Key/CommandDescription
history nShows the stuff typed – add a number to limit the last n items
Ctrl + rInteractively search through previously typed commands
![value]Execute the last command typed that starts with ‘value’
![value]:pPrint to the console the last command typed that starts with ‘value’
!!Execute the last command typed
!!:pPrint to the console the last command typed

FILE MANAGEMENT Link to heading

Key/CommandDescription
touch [file]Create a new file
pwdFull path to working directory
.Current folder, e.g. ls .
..Parent/enclosing directory, e.g. ls ..
ls -l ..Long listing of parent directory
cd ../../Move 2 levels up
catConcatenate to screen
rm [file]Remove a file, e.g. rm data.tmp
rm -i [file]Remove with confirmation
rm -r [dir]Remove a directory and contents
rm -f [file]Force removal without confirmation
cp [file] [newfile]Copy file to file
cp [file] [dir]Copy file to directory
mv [file] [new filename]Move/Rename, e.g. mv file1.ad /tmp
pbcopy < [file]Copies file contents to clipboard
pbpastePaste clipboard contents
pbpaste > [file]Paste clipboard contents into file, pbpaste > paste-test.txt

DIRECTORY MANAGEMENT Link to heading

Key/CommandDescription
mkdir [dir]Create new directory
mkdir -p [dir]/[dir]Create nested directories
rmdir [dir]Remove directory ( only operates on empty directories )
rm -R [dir]Remove directory and contents
less [file]Output file content delivered in screensize chunks
[command] > [file]Push output to file, keep in mind it will get overwritten
[command] » [file]Append output to existing file
[command] < [file]Tell command to read content from a file
Key/CommandDescription
find [dir] -name [search_pattern]Search for files, e.g. find /Users -name "file.txt"
grep [search_pattern] [file]Search for all lines that contain the pattern, e.g. grep "Tom" file.txt
grep -r [search_pattern] [dir]Recursively search in all files in specified directory for all lines that contain the pattern
grep -v [search_pattern] [file]Search for all lines that do NOT contain the pattern
grep -i [search_pattern] [file]Search for all lines that contain the case-insensitive pattern
mdfind [search_pattern]Spotlight search for files (names, content, other metadata), e.g. mdfind skateboard
mdfind -onlyin [dir] -name [pattern]Spotlight search for files named like pattern in the given directory

HELP Link to heading

Key/CommandDescription
[command] -hOffers help
[command] –helpOffers help
info [command]Offers help
man [command]Show the help manual for [command]
whatis [command]Gives a one-line description of [command]
apropos [search-pattern]Searches for command with keywords in description