Keyboard shortcuts can help you better navigate software interfaces. The following sections define shortcuts for the GNU/Linux command line interface (CLI). Mastering these shortcuts will make you a more adept GNU/Linux user and help you efficiently accomplish your tasks.
Note: If you are not familiar with the GNU/Linux command line interface, review the Conventions page before proceeding.
Moving Around
- Ctrl+a or Home
- Move to the beginning of the line.
- Ctrl+e or End
- Move to the end of the line.
- Alt+b
- Move one word back.
- Alt+f
- Move one word forward.
- Ctrl+b
- Move one character back.
- Ctrl+f
- Move one character forward.
- Ctrl+xx
- Move between the cursor position and the beginning of the line. You can use this shortcut to repeatedly move between the cursor position and the beginning of the line.
Command Editing
- Ctrl+u
- Cut the text from before the cursor position to the beginning of the line.
- Ctrl+k
- Cut the text from after the cursor position to the end of the line.
- Ctrl+w
- Cut the word before the cursor.
- Ctrl+y
- Paste the buffer contents at the cursor position.
- Alt+u
- Capitalize every character from the cursor position to the end of the current word.
- Alt+l
- Lowercase every character from the cursor position to the end of the current word.
- Alt+c
- Capitalize the character under the cursor position. The cursor will then move to the end of the current word.
- Alt+t
- Swap the current word with the previous word.
- Ctrl+t
- Swap the character at the cursor with the character preceding it.
- Ctrl+Shift+_
- Undo last key press.
- Ctrl+h or Backspace
- Delete the character before the cursor.
- Ctrl+d or Delete
- Delete the character under the cursor.
- Alt+d
- Delete the current word.
Screen Control
- Ctrl+l
- Clear the screen.
- Ctrl+s
- Stop output to the screen.
- Ctrl+q
- Resume output to the screen.
Job Control
- Ctrl+z
- Suspend the foreground process. From here, you can unsuspend the process by entering fg, or place it in the background by entering bg.
- Ctrl+c
- Kill the foreground process by sending it a
SIGINT
signal. - Ctrl+d
- Exit the current shell by sending an End-of-file (EOF) marker to
bash
. This is similar to running theexit
command.
Command History
- ↑ or Ctrl+p
- Go to the previous command in the command history.
- ↓ or Ctrl+n
- Go to the next command in the command history.
- Alt+r
- Revert the changes to a command that you have pulled from the command history.
- Ctrl+r
- Activate recursive search. Recalls the last command in the command history that matches the characters that you provide. Can be pressed multiple times to move backward in the command history.
- Enter Ctrl+Shift+r to move forward in the command history. Enter Escape to exit recursive search with the command that you have found placed onto the command line (but not executed).
- Ctrl+o
- Run a command found with recursive search and place the next command in the command history on the command line (but not execute it) afterwards.
- Ctrl+g
- Exit command recursive search mode without running any commands or placing any commands on the command line.
Tab Completion
- Tab
- Auto-complete files, directories, and binaries.
- When you press the Tab key, the shell completes an incomplete input if the continuation can be uniquely identified. For the first word of a command,
bash
considers all executable programs. Within the rest of the command line,bash
considers all files in the current or specified directory. - If several commands or files exist whose names start out equal,
bash
completes the name as far as possible and then acoustically signals that the command or filename may still be incomplete. Another Tab lists the remaining possibilities.
Emacs and vi Mode
By default, most GNU/Linux distributions CLIs are set to use the emacs
-style keys that were previously discussed. You can confirm what settings your system is using by displaying the contents of the SHELLOPTS
variable:
$ echo "${SHELLOPTS}"
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
If you prefer to use vi
-style keys, you can do so with the set
command:
$ set -o vi && echo "${SHELLOPTS}"
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi
Documentation
To learn more about the different style keys that the Bash shell supports, refer to its man page, either on the command line (man 1 bash
) or online.