Wednesday, 9 September 2020
Key/
Comm Description
and
Go to the beginning of the line you are currently
typing on. This also works for most text input
Ctrl + A
fields system wide. Netbeans being one
exception
Go to the end of the line you are currently
typing on. This also works for most text input
Ctrl + E
fields system wide. Netbeans being one
exception
Ctrl + L Clears the Screen
Cmd +
Clears the Screen
K
Ctrl + U Cut everything backwards to beginning of line
Ctrl + K Cut everything forward to end of line
Ctrl + Cut one word backwards using white space as
W delimiter
Paste whatever was cut by the last cut
Ctrl + Y
command
Ctrl + H Same as backspace
Kill whatever you are running. Also clears
Ctrl + C
everything on current line
Exit the current shell when no process is
Ctrl + D
running, or send EOF to a the running process
Puts whatever you are running into a
Ctrl + Z
suspended background process. fg restores it
1
Wednesday, 9 September 2020
Undo the last command. (Underscore. So it's
Ctrl + _
actually Ctrl + Shift + minus)
Ctrl + T Swap the last two characters before the cursor
Ctrl + F Move cursor one character forward
Ctrl + B Move cursor one character backward
Option
Move cursor one word forward
+→
Option
Move cursor one word backward
+←
Esc + T Swap the last two words before the cursor
Esc +
Cut one word backwards using none
Backsp
alphabetic characters as delimiters
ace
Tab Auto-complete files and folder names
CORE COMMANDS
Key/
Comman Description
d
cd [folder] Change directory e.g. cd Documents
cd Home directory
cd ~ Home directory
cd / Root of drive
cd - Previous directory
ls Short listing
2
Wednesday, 9 September 2020
ls -l Long listing
ls -a Listing incl. hidden files
ls -lh Long listing with Human readable file sizes
ls -R Entire content of folder recursively
sudo
Run command with the security privileges of
[command
the superuser (Super User DO)
]
open [file] Opens a file ( as if you double clicked it )
top Displays active processes. Press q to quit
nano [file] Opens the file using the nano editor
vim [file] Opens the file using the vim editor
clear Clears the screen
reset Resets the terminal display
CHAINING COMMANDS
Key/Command Description
[command-a]; Run command A and then B,
[command-b] regardless of success of A
[command-a] &&
Run command B if A succeeded
[command-b]
[command-a] ||
Run command B if A failed
[command-b]
[command-a] & Run command A in background
PIPING COMMANDS
3
Wednesday, 9 September 2020
Key/
Description
Command
[command-a] Run command A and then pass the
| [command- result to command B e.g ps auxwww |
b] grep google
COMMAND HISTORY
Key/
Description
Command
Shows the stuff typed – add a number to
history n
limit the last n items
Interactively search through previously
Ctrl + r
typed commands
Execute the last command typed that starts
![value]
with ‘value’
Print to the console the last command typed
![value]:p
that starts with ‘value’
!! Execute the last command typed
!!:p Print to the console the last command typed
FILE MANAGEMENT
Key/
Description
Command
touch [file] Create a new file
pwd Full path to working directory
. Current folder, e.g. ls .
4
Wednesday, 9 September 2020
.. Parent/enclosing directory, e.g. ls ..
ls -l .. Long listing of parent directory
cd ../../ Move 2 levels up
cat Concatenate to screen
rm [file] Remove a file, e.g. rm [Link]
rm -i [file] Remove with confirmation
rm -r [dir] Remove a directory and contents
rm -f [file] Force removal without confirmation
cp [file]
Copy file to file
[newfile]
cp [file] [dir] Copy file to directory
mv [file] [new
Move/Rename, e.g. mv [Link] /tmp
filename]
pbcopy < [file] Copies file contents to clipboard
pbpaste Paste clipboard contents
Paste clipboard contents into file,
pbpaste > [file]
pbpaste > [Link]
DIRECTORY MANAGEMENT
Key/
Description
Command
mkdir [dir] Create new directory
mkdir -p [dir]/
Create nested directories
[dir]
5
Wednesday, 9 September 2020
Remove directory ( only operates on
rmdir [dir]
empty directories )
rm -R [dir] Remove directory and contents
Output file content delivered in
less [file]
screensize chunks
[command] > Push output to file, keep in mind it will
[file] get overwritten
[command] >>
Append output to existing file
[file]
[command] < Tell command to read content from a
[file] file
SEARCH
Key/Command Description
find [dir] -name Search for files, e.g. find /Users
[search_pattern] -name "[Link]"
grep
Search for all lines that contain the
[search_pattern]
pattern, e.g. grep "Tom" [Link]
[file]
grep -r Recursively search in all files in
[search_pattern] specified directory for all lines that
[dir] contain the pattern
grep -v
Search for all lines that do NOT contain
[search_pattern]
the pattern
[file]
grep -i
Search for all lines that contain the
[search_pattern]
case-insensitive pattern
[file]
6
Wednesday, 9 September 2020
Spotlight search for files (names,
mdfind
content, other metadata), e.g. mdfind
[search_pattern]
skateboard
mdfind -onlyin
Spotlight search for files named like
[dir] -name
pattern in the given directory
[pattern]
HELP
Key/Command Description
[command] -h Offers help
[command] --help Offers help
info [command] Offers help
Show the help manual for
man [command]
[command]
Gives a one-line description of
whatis [command]
[command]
apropos [search- Searches for command with
pattern] keywords in description
•