Bash and zsh keyboard shortcuts: moving around the line, deleting words, searching your history and controlling commands.
These shortcuts work in bash — the default shell on Linux — and in zsh. In the macOS Terminal, the Alt key is Option; for shortcuts that use it to work, turn on “Use Option as Meta key” in your terminal profile settings.
Moving around the line
| Ctrl+A / Ctrl+E | go to the start / end of the line |
| Alt+B / Alt+F | move back / forward one word |
| Ctrl+XX | jump between the start of the line and the current position (bash) |
Deleting and pasting
| Ctrl+W | delete the word before the cursor |
| Alt+D | delete the word after the cursor |
| Ctrl+U | delete everything back to the start of the line (in zsh, the whole line) |
| Ctrl+K | delete everything to the end of the line |
| Ctrl+Y | paste the text you deleted last |
| Ctrl+_ | undo the last change |
Command history
| ↑ / ↓ | previous / next command |
| Ctrl+R | search your history: start typing, press Ctrl+R again for an older match, Enter to run it, the right arrow to edit it before running, Ctrl+G to leave the search |
| Alt+. | insert the last argument of the previous command; press again to go back through earlier commands |
!! | the whole previous command — for example, sudo !! if you forgot sudo |
history | list your recent commands |
Controlling commands
| Tab | complete a command, file or directory name; press twice to list the options |
| Ctrl+C | interrupt the running command |
| Ctrl+Z | suspend the command; resume it with fg, or resume it in the background with bg |
| Ctrl+D | on an empty line, exit the shell or close the SSH session |
| Ctrl+L | clear the screen |
| Ctrl+X Ctrl+E | open the current line in your editor — handy for long commands (bash) |
Tip If the terminal stops responding to keys after you accidentally press Ctrl+S, press Ctrl+Q — that pauses the output; it hasn’t frozen.
Didn’t find the answer? Ask our support team — we’ll help.