Bash keyboard shortcuts
Bash and Zsh use the same Emacs-style line editing keys in every terminal: on Linux, in the macOS Terminal and in WSL or Git Bash on Windows. They move the cursor, cut and paste words, search history and control running programs.
Most used Bash keyboard shortcuts
The Bash shortcuts worth learning first. The full list follows, grouped by task.
- Go to the start of the lineMacCtrlALinuxCtrlAWindowsCtrlA
- Go to the end of the lineMacCtrlELinuxCtrlEWindowsCtrlE
- Cut from the cursor to the start of the lineMacCtrlULinuxCtrlUWindowsCtrlU
- Cut from the cursor to the end of the lineMacCtrlKLinuxCtrlKWindowsCtrlK
- Cut the word before the cursorMacCtrlWLinuxCtrlWWindowsCtrlW
- Search history backwardsMacCtrlRLinuxCtrlRWindowsCtrlR
- Complete the command or file nameMacTabLinuxTabWindowsTab
- Stop the running programMacCtrlCLinuxCtrlCWindowsCtrlC
- Suspend the running programMacCtrlZLinuxCtrlZWindowsCtrlZ
- Clear the screenMacCtrlLLinuxCtrlLWindowsCtrlL
Moving the cursor
7 shortcuts| Action | Mac | Linux | Windows |
|---|---|---|---|
| Go to the start of the line | CtrlA | CtrlA | CtrlA |
| Go to the end of the line | CtrlE | CtrlE | CtrlE |
| Back one word | OptionB | AltB | AltB |
| Forward one word | OptionF | AltF | AltF |
| Back one character | CtrlB | CtrlB | CtrlB |
| Forward one character | CtrlF | CtrlF | CtrlF |
| Jump between the start of the line and the cursor | CtrlX,CtrlX | CtrlX,CtrlX | CtrlX,CtrlX |
Cutting and pasting
14 shortcuts| Action | Mac | Linux | Windows |
|---|---|---|---|
| Cut from the cursor to the start of the line | CtrlU | CtrlU | CtrlU |
| Cut from the cursor to the end of the line | CtrlK | CtrlK | CtrlK |
| Cut the word before the cursor | CtrlW | CtrlW | CtrlW |
| Cut the word after the cursor | OptionD | AltD | AltD |
| Paste the last cut text | CtrlY | CtrlY | CtrlY |
| Delete the character before the cursor | CtrlH | CtrlH | CtrlH |
| Delete the character under the cursorLine has text | CtrlD | CtrlD | CtrlD |
| Swap the last two characters | CtrlT | CtrlT | CtrlT |
| Swap the last two words | OptionT | AltT | AltT |
| Uppercase the word | OptionU | AltU | AltU |
| Lowercase the word | OptionL | AltL | AltL |
| Capitalise the word | OptionC | AltC | AltC |
| Undo the last edit | CtrlX,CtrlU | CtrlX,CtrlU | CtrlX,CtrlU |
| Edit the command in your editor | CtrlX,CtrlE | CtrlX,CtrlE | CtrlX,CtrlE |
History
6 shortcuts| Action | Mac | Linux | Windows |
|---|---|---|---|
| Search history backwards | CtrlR | CtrlR | CtrlR |
| Cancel the history searchSearching history | CtrlG | CtrlG | CtrlG |
| Previous command | CtrlPor↑ | CtrlPor↑ | CtrlPor↑ |
| Next command | CtrlNor↓ | CtrlNor↓ | CtrlNor↓ |
| Insert the last argument of the previous command | Option. | Alt. | Alt. |
| Run the command and fetch the next from history | CtrlO | CtrlO | CtrlO |
Completion
2 shortcuts| Action | Mac | Linux | Windows |
|---|---|---|---|
| Complete the command or file name | Tab | Tab | Tab |
| List all completions | Tab,Tab | Tab,Tab | Tab,Tab |
Programs and screen
7 shortcuts| Action | Mac | Linux | Windows |
|---|---|---|---|
| Stop the running program | CtrlC | CtrlC | CtrlC |
| Suspend the running program | CtrlZ | CtrlZ | CtrlZ |
| Quit the program and dump core | Ctrl\ | Ctrl\ | Ctrl\ |
| End of input; exits the shell on an empty lineEmpty line | CtrlD | CtrlD | CtrlD |
| Clear the screen | CtrlL | CtrlL | CtrlL |
| Pause output | CtrlS | CtrlS | CtrlS |
| Resume output | CtrlQ | CtrlQ | CtrlQ |
No shortcuts match. Try fewer words, the key names only, or search every app.
Show the key map: which keys Bash uses mostDarker orange = used by more shortcuts
Using the Alt shortcuts in the Mac Terminal
Shortcuts written with Option on a Mac send the Meta key. The macOS Terminal does not do that out of the box.
- Terminal
- Open Terminal > Settings > Profiles > Keyboard and tick Use Option as Meta key.
- iTerm2
- Open Settings > Profiles > Keys and set Left Option key to Esc+.
- Without the setting
- Press Esc and then the letter instead: Esc then B moves back one word.
Bash keyboard shortcuts: questions
- How do I search my command history in the terminal?
- Press Ctrl+R and start typing: the most recent matching command appears. Press Ctrl+R again for older matches, Enter to run it, or Ctrl+G to give up.
- What does Ctrl+Z do in the terminal?
- It suspends the running program and returns you to the prompt. Type fg to bring it back to the foreground or bg to keep it running in the background.
These are the default key bindings in Bash and Zsh Bash 5.2 / Zsh 5.9, as published by GNU Project. Shortcuts that need an extension, an add-in or a changed keymap are left out. Where two combinations do the same thing, both are shown.
Single-system lists: Bash keyboard shortcuts for Mac, Bash keyboard shortcuts for Linux, Bash keyboard shortcuts for Windows.
Each shortcut has its own page with the keys for every system, related shortcuts and the same action in other apps. The printable cheat sheet fits the whole list on one or two pages.