Skip to content
RIPE NCC member · Local Internet RegistryCall us on 020 3318 3449sales@hosting-telecom.uk

Command-line keyboard shortcuts

Bash and zsh keyboard shortcuts: moving around the line, deleting words, searching your history and controlling commands.

Contents

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+Ego to the start / end of the line
Alt+B / Alt+Fmove back / forward one word
Ctrl+XXjump between the start of the line and the current position (bash)

Deleting and pasting

Ctrl+Wdelete the word before the cursor
Alt+Ddelete the word after the cursor
Ctrl+Udelete everything back to the start of the line (in zsh, the whole line)
Ctrl+Kdelete everything to the end of the line
Ctrl+Ypaste the text you deleted last
Ctrl+_undo the last change

Command history

↑ / ↓previous / next command
Ctrl+Rsearch 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
historylist your recent commands

Controlling commands

Tabcomplete a command, file or directory name; press twice to list the options
Ctrl+Cinterrupt the running command
Ctrl+Zsuspend the command; resume it with fg, or resume it in the background with bg
Ctrl+Don an empty line, exit the shell or close the SSH session
Ctrl+Lclear the screen
Ctrl+X Ctrl+Eopen 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.

Choose which cookies we may use. You can change your mind at any time with the “Cookie settings” link at the bottom of every page.

Necessary

Always active

They keep the site secure and remember your cookie choice. They don’t identify you.

Google Analytics counts visits and shows which pages people find useful, so we can improve the site. Which cookies