Terminal / Bash (readline) keyboard shortcuts
Terminal / Bash (readline) keyboard shortcuts
75 shortcuts
Windows, macOS and Linux
The command line itself: the default Emacs-mode line editing that GNU Readline gives Bash, plus the control characters the terminal driver handles before the shell ever sees them. The same keys work in most other Readline-based shells and REPLs on Linux, macOS and WSL. Readline writes Alt as M-, so M-f below is Alt + F; if Alt does nothing in your terminal, press Esc and then the key instead.
Moving the cursor
| Shortcut | What it does |
|---|---|
| Ctrl + A | Move to the start of the line |
| Ctrl + E | Move to the end of the line |
| Ctrl + F | Move forward one character |
| Ctrl + B | Move back one character |
| Alt + F | Move forward one word |
| Alt + B | Move back one word |
| Ctrl + @ | Set the mark at the cursor — Alt + Space does the same |
| Ctrl + X then Ctrl + X | Swap the cursor and the mark |
Editing the line
| Shortcut | What it does |
|---|---|
| Ctrl + D | Delete the character under the cursor — On an empty line this sends end-of-file and closes the shell |
| Backspace | Delete the character before the cursor |
| Ctrl + K | Cut from the cursor to the end of the line |
| Ctrl + U | Cut from the cursor back to the start of the line |
| Ctrl + X then Backspace | Cut to the start of the line |
| Ctrl + W | Cut the whitespace-delimited word before the cursor |
| Alt + Backspace | Cut the word before the cursor |
| Alt + D | Cut the word after the cursor |
| Ctrl + Y | Paste the most recently cut text |
| Alt + Y | Cycle back through the kill ring — Only valid straight after Ctrl + Y |
| Ctrl + T | Transpose the two characters around the cursor |
| Alt + T | Transpose the two words around the cursor |
| Ctrl + _ | Undo the last edit — Ctrl + X then Ctrl + U does the same |
| Alt + R | Revert the line to its original history entry |
| Alt + \ | Delete the whitespace around the cursor |
| Ctrl + V | Insert the next keystroke literally — Ctrl + Q does the same; use it to type a control character |
Case and text expansion
| Shortcut | What it does |
|---|---|
| Alt + U | Uppercase to the end of the word |
| Alt + L | Lowercase to the end of the word |
| Alt + C | Capitalise the word |
| Alt + # | Comment out the line and accept it — Puts the command in history without running it |
| Alt + & | Expand the tilde before the cursor |
History
| Shortcut | What it does |
|---|---|
| Ctrl + P | Recall the previous command |
| Ctrl + N | Recall the next command |
| Alt + < | Jump to the first entry in history |
| Alt + > | Jump to the end of history |
| Ctrl + R | Search backwards through history as you type |
| Ctrl + S | Search forwards through history — Often swallowed by terminal flow control; run stty -ixon to free it |
| Alt + P | Search history backwards without incremental matching |
| Alt + N | Search history forwards without incremental matching |
| Alt + . | Insert the last argument of the previous command — Press again to walk further back |
| Alt + Ctrl + Y | Insert the first argument of the previous command |
| Ctrl + O | Run the line and then recall the one after it — Replays a run of history commands in order |
| Ctrl + X then Ctrl + E | Open the current line in your editor |
| Alt + Ctrl + E | Expand aliases, variables and history on the line |
| Alt + ^ | Expand the history reference on the line |
Completion
| Shortcut | What it does |
|---|---|
| Tab | Complete the word before the cursor |
| Alt + ? | List the possible completions |
| Alt + * | Insert every possible completion at once |
| Alt + / | Complete as a filename |
| Alt + ~ | Complete as a username |
| Alt + $ | Complete as a shell variable |
| Alt + @ | Complete as a hostname |
| Alt + ! | Complete as a command name |
| Ctrl + X then / | List possible filename completions |
| Ctrl + X then ~ | List possible username completions |
| Ctrl + X then $ | List possible variable completions |
| Ctrl + X then @ | List possible hostname completions |
| Ctrl + X then ! | List possible command completions |
| Alt + Tab | Complete from words already in history |
| Alt + { | Complete and wrap the matches in brace expansion |
Signals and job control
| Shortcut | What it does |
|---|---|
| Ctrl + C | Interrupt the running command |
| Ctrl + Z | Suspend the running command to the background |
| Ctrl + D | Send end-of-file to close the shell or the input stream |
| Ctrl + \ | Quit the running command and dump core |
| Ctrl + S | Freeze terminal output |
| Ctrl + Q | Resume frozen terminal output |
Screen, macros and setup
| Shortcut | What it does |
|---|---|
| Ctrl + L | Clear the screen and redraw the prompt |
| Alt + Ctrl + L | Clear the screen and the scrollback |
| Ctrl + G | Abort the current editing command |
| Ctrl + X then ( | Start recording a keyboard macro |
| Ctrl + X then ) | Stop recording the macro |
| Ctrl + X then E | Play back the recorded macro |
| Ctrl + X then Ctrl + R | Reload ~/.inputrc |
| Ctrl + X then Ctrl + V | Show the shell version |
| Ctrl + ] | Jump forward to the next occurrence of a character |
| Alt + Ctrl + ] | Jump back to the previous occurrence of a character |
| Ctrl + X then S | Spell-correct the word before the cursor |
Common questions
- How many keyboard shortcuts does Terminal / Bash (readline) have?
- This page lists 75 shortcuts across 7 groups, covering the ones people actually use day to day rather than every binding the application defines.
- Are Terminal / Bash (readline) shortcuts the same on Mac and Windows?
- Mostly. The usual difference is that Ctrl on Windows becomes ⌘ on macOS, which is why the shortcuts here are written as "Ctrl/⌘". Where a binding genuinely differs beyond that swap, it is spelled out separately.
Related pages
Sources
- Official vendor product documentation — At One Place