Commandline Cheatsheet
Basic Navigation
| Keystroke | What It Does |
|---|---|
C-a |
Move to beginning of line |
C-e |
Move to end of line |
C-k |
Delete from current position to end of line |
C-u |
Delete from current position to beginning of line |
Esc-bEsc-leftarrowAlt-b |
Move cursor backward to previous word |
Esc-fEsc-rightarrowAlt-f |
Move cursor forward to beginning of next word |
C-l |
Clear the screen |
C-c |
Cancel the current command |
C-w |
Delete previous word |
Esc-dAlt-d |
Delete next word |
Using History
| Command | Example | What It Does |
|---|---|---|
history |
history |
Display the history of commands |
!! |
!! |
Expand to the last command |
!n |
!51 |
Expand to command numbered 51 in history |
!word |
!ssh |
Expand to last command starting with keyword ssh |
!?word? |
!?commit? |
Expand to last command which includes the keyword commit |
^oldword^newword |
^commt^commit |
Replace commt in the last command with commit |
!!:^ |
!!:^ or !!:1 |
Expand to first argument of previous command |
!!:$ |
!!:$ |
Expand to last argument of previous command |
!!:* |
!!:* |
Expand to all arguments of previous command |
Interactive Search
| Keystroke | What It Does |
|---|---|
C-r |
Start interactive search of command history, or move to next matching result |
C-s |
Move to previous matching result (needs stty -ixon to disable C-s from freezing terminal) |
C-g |
Cancel interactive search |