Show Menu
Cheatography

Z Shell Cheat Sheet (DRAFT) by

zsh tips and shortcuts

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Command Line

^a
Start of command line
^e
End of command line
^u
Delete line
^k
Delete forward to end of line
^w
Delete previous word
^t
Swap previous and current character

Process Manipu­lation

^d
Exit shell
^l
Clear screen
^c
Kill process
^z
Suspend process
bg
Continue process in backgroup
fg
Restore process to foreground
^s
Pause terminal output
^q
Resume terminal output
 

Command History

!!
Previous command line (i.e. !-1)
!foo
Most recent command line starting with foo
!?foo
Most recent command line containing foo
!*
All arguments of previous command
!^
First argument of previous command
!$
Last argument of previous command
^foo^bar
Replace foo with bar in previous command
!n
nth command line in history
!-n
nth command line from current one
 

regex Characters

Expression
Explan­ation
Example
Match
\d
One digit
1\d3
123
\w
One character
f\wo
foo
\s
One space (space, tab, newline, carriage return)
abc\s123
abc 123
\D
One character NOT a digit
b\Dr
bar
\W
One character NOT a word character
4\W6
456
\S
One character NOT a space
a\Sc 1\S3
abc 123
.
Any character
a.c.1.3
abc 123
\
Escapes a special character
\[\.*\]
[.*]
\t \n \r
tab, linefeed, carriage return
\r\n
Line separator on Windows
Quanti­fiers
*
Zero or more (greedy)
fob
foo
+
One or more (greedy)
f+
foo
?
One or none (lazy)
fool?
foo
{3}
Exactly three time
\w{3}
foo
{2,4}
Two to four times (greedy)
\D{2,4}
foo
{2,}
Two or more times (greedy)
.{2,}
foo
Logic
|
OR
foo|bar
foo
"­laz­y" means match the smallest amount. "­gre­edy­" means match the largest amount. \d+ matches x123x while \d* matches x123x