Show Menu
Cheatography

Bash/ZSH Shourtcuts Cheat Sheet by

Keyboard shortcuts and expansion reference.

Bash/ZSH Keyboard Shortcuts

Tab
Auto complete
^a
Beginning of line
^e
End of line
^f
Forward one character
^b
Back one character
^h
Delete one character (backw­ards)
%f
Forward one word
%b
Back one word
^w
Delete one word (backw­ards)
^u
Clear to beginning of line
^k
Clear to end of line
^y
Paste from Kill Ring
^t
Swap cursor with previous character
%t
Swap cursor with previous word
^p
Previous line in history
^n
Next line in history
^r
Search backwards in history
^l
Clear screen
^o
Execute command but keep line
^z
Suspend process
fg
restore process
bg
continue process in background
^c
Kill current process
^d
Exit shell
^ - Hold Control while pressing key
% - Hold meta (alt, or command on mac)
 

Bash Parameter Expansions

${para­meter}
Value of parameter
${para­met­er:­-word}
Use default
${para­met­er:­=word}
Assign default
${para­met­er:­?word}
Display Error
${para­met­er:­+word}
Use Alternate
${para­met­er:­offset}
Substring
${para­met­er:­off­set­:le­ngth}
${!nam­e[@]}
List Array Keys
${#par­ameter}
Parameter length
${para­met­er#­match}
Remove prefix
${para­met­er#­#match}
(longest)
${para­met­er%­match}
Remove suffix
${para­met­er%­%match}
(longest)
${para­met­er/­pat­ter­n/s­tring}
Substi­tution
${para­met­er^­pat­tern}
Uppercase match
${para­met­er^­^pa­ttern}
Uppercase all
${para­met­er,­pat­tern}
Lowercase match
${para­met­er,­,pa­ttern}
Lowercase all

Rockstar Penguin

 

Sed commands

:[label]
Set label
Zero/One address commands
=
Print current line number
a \
Append text
text
(embedded newlines)
Address range commands
b [label]
Jump to label
t (T) [label]
Jump to label on (failed) s///
c \
Replace match
text
(Embedded newlines)
d (D)
Delete (to newline)
h H
Copy/A­ppend pattern
g G
Paste/­Append hold
x
Exchange hold/p­attern
n N
Read/A­ppend next line
p
Print pattern
s/rege­x/r­eplace/
Substi­tution
Addresses
first~step
Starting at first, every stepth
/regex/
Lines matching regex
addr1,+N
addr1 and N following lines
Various
{c1;c2­;c3;}
List of commands
;
Separate commands
Using GNU Sed 4.2.2. Handy one-li­ners: http:/­/se­d.s­our­cef­org­e.n­et/­sed­1li­ne.txt
               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Bash Script Colors Cheat Sheet
          Linux Every Day Commands Cheat Sheet