ShareYourGroupShareYourGroupKeyboard Shortcuts

Programs · 36 shortcuts

Linux and Mac terminal keyboard shortcuts

The command line looks unfriendly until you learn a dozen keys. Then it becomes quick: you stop retyping commands, stop holding the arrow key to reach the start of a line, and know how to stop a program that has run away. These shortcuts work in Bash and Zsh, the shells used by Linux, by the Mac's Terminal, by Git Bash on Windows and by the Windows Subsystem for Linux.

They use the Ctrl key on every system, the Mac included.

The eight to learn first

  1. Tab completes the command or file name you have started typing. Press it twice to see the choices.
  2. Up arrow brings back the previous command.
  3. Ctrl + R searches your history: type a few letters and the last matching command appears.
  4. Ctrl + C stops the program that is running.
  5. Ctrl + A and Ctrl + E jump to the start and the end of the line.
  6. Ctrl + U clears everything you have typed on the line.
  7. Ctrl + L clears the screen.
  8. Ctrl + D closes the shell, the same as typing exit.
KeysWhat it does
Ctrl + AGo to the start of the line
Ctrl + EGo to the end of the line
Alt + BGo back one word
Alt + FGo forward one word
Ctrl + B or Left arrowGo back one character
Ctrl + F or Right arrowGo forward one character
Ctrl + X then Ctrl + XJump between the start of the line and where you were
KeysWhat it does
Ctrl + UDelete from the cursor back to the start of the line
Ctrl + KDelete from the cursor to the end of the line
Ctrl + WDelete the word before the cursor
Alt + DDelete the word after the cursor
Ctrl + H or BackspaceDelete the character before the cursor
Ctrl + D or DeleteDelete the character under the cursor
Ctrl + YPaste back what was last deleted with Ctrl + U, Ctrl + K or Ctrl + W
Ctrl + _Undo the last change to the line
Ctrl + TSwap the two characters before the cursor
KeysWhat it does
Up arrow or Ctrl + PShow the previous command
Down arrow or Ctrl + NShow the next command
Ctrl + RSearch back through the history as you type
Ctrl + R againGo to the next older match
Ctrl + GLeave the history search without running anything
Alt + .Insert the last word of the previous command
!! then EnterRun the previous command again
KeysWhat it does
Ctrl + CStop the running program
Ctrl + ZPause the running program and return to the prompt
Ctrl + DSend "end of input"; at an empty prompt, close the shell
Ctrl + LClear the screen
Ctrl + SFreeze the output on screen
Ctrl + QUnfreeze the output
TabComplete a command, file or folder name
Tab twiceList all the possible completions
KeysWhat it does
Ctrl + Shift + CCopy the selected text, in most Linux terminals
Ctrl + Shift + VPaste, in most Linux terminals
Ctrl + Shift + TOpen a new tab, in most Linux terminals
Ctrl + Shift + WClose the tab
Ctrl + Alt + TOpen a terminal, on Ubuntu and several other systems

On the Mac, the window shortcuts use Command: Cmd + C, Cmd + V, Cmd + T and Cmd + W.

Ctrl + C does not copy here

In a terminal, Ctrl + C means "stop". It interrupts whatever is running. That is why Linux terminals use Ctrl + Shift + C and Ctrl + Shift + V for copy and paste, and why pressing Ctrl + C out of habit to copy can end a long job. On the Mac there is no clash, since copy is Cmd + C.

The screen has frozen

If the terminal stops showing anything you type, you have probably pressed Ctrl + S, which pauses the output. Nothing is broken. Press Ctrl + Q to release it.

Paused is not stopped

Ctrl + Z does not end a program. It suspends it, and the program waits in the background. Type fg to bring it back, or jobs to see what is waiting. To end a program, use Ctrl + C.

History search is the biggest time saver

Press Ctrl + R and type part of a command you ran earlier, such as "ssh" or a file name. The most recent match appears. Press Ctrl + R again for older ones, Enter to run the command, or the right arrow to put it on the line for editing. Long commands need typing only once.

Tab completion prevents typing mistakes

Type the first letters of a file or folder name and press Tab. If only one thing matches, the shell finishes the name for you, with the spelling and the capital letters right. If several match, a second Tab lists them. Experienced users press Tab constantly, as much to check that a file exists as to save typing.

The Alt key on a Mac

In the Mac's Terminal, the Option key does not act as Alt until you tick "Use Option as Meta key" in the Terminal settings, under Profiles, Keyboard. Without that, press Esc and then the letter: Esc then B goes back a word.

Where these come from

Most of these keys belong to a library called Readline, which Bash uses for editing the line. Their letters come from the Emacs editor: A for the start, E for end, K for kill. The same keys work in many other command-line programs, including the Python prompt. For the commands themselves, see our Commands site.

This is an independent reference site. It is not connected with Microsoft, Apple, Google or any other maker of the programs named here. Product names belong to their owners and are used only to say where a shortcut works. Programs change; if a shortcut does not work for you, check the program's own help.