Skip to main content

Bash Keyboard Shortcuts Cheatsheet

By Dejan Panovski •Updated on • Download PDF

Bash keyboard shortcuts for editing commands, searching history, completing words, and controlling foreground jobs.

Edit long commands and find earlier ones without retyping them. These shortcuts use Bash’s default Emacs editing mode. Hold Ctrl or Alt with the named key; if Alt does not work, press and release Esc, then press the other key. Sequences containing ‘then’ are pressed in order.

Move the Cursor

Move within the command you are editing, including commands that wrap across screen lines.

ShortcutAction
Ctrl+AGo to the start of the line
Ctrl+EGo to the end of the line
Ctrl+BMove back one character
Ctrl+FMove forward one character
Alt+BGo to the start of this or the previous word
Alt+FGo to the end of this or the next word

Readline treats letters and digits as words for Alt+B and Alt+F; punctuation separates words.

Cut and Paste Text

Cut text goes into Readline’s kill ring, separate from your desktop clipboard.

ShortcutAction
Ctrl+UCut from the cursor back to the start of the line
Ctrl+KCut from the cursor to the end of the line
Ctrl+WCut the previous whitespace-delimited word
Alt+DCut to the end of this or the next word
Alt+BackspaceCut back to the start of this or the previous word
Ctrl+YPaste the most recently cut text at the cursor
Alt+YAfter Ctrl+Y, cycle through earlier cuts

To cut the whole line, press Ctrl+A, then Ctrl+K. Ctrl+U alone leaves text after the cursor in place.

Correct and Undo Edits

These shortcuts change the current input line, not commands that have already run.

ShortcutAction
BackspaceDelete the character before the cursor
Ctrl+DDelete the character at the cursor; see the empty-line caveat below
Ctrl+_Undo the last edit; repeat to undo more
Ctrl+X then Ctrl+UAnother binding for undo
Alt+RUndo all edits to this line
Ctrl+TSwap the character before the cursor with the one at it; at line end, swap the last two
Alt+TSwap the word before the cursor with the one after it; at line end, swap the last two
Alt+U, Alt+L, Alt+CUppercase, lowercase, or capitalize from the cursor to the end of the word
Ctrl+X then Ctrl+EOpen the line in your text editor; Bash runs it when you exit, so delete the text to cancel

Recall Commands and Arguments

Recall a command, edit it, and press Enter when you are ready to run it.

ShortcutAction
Ctrl+P or UpRecall the previous command
Ctrl+N or DownRecall the next command
Alt+<Go to the oldest entry in the current history list
Alt+>Return to the input line after the newest history entry
Alt+.Insert the previous command’s last argument; repeat to use earlier commands

Alt+< and Alt+> use the literal < and > characters, which may require Shift on your keyboard.

Search Command History

Press Ctrl+R, then type part of a command to search backward through Bash history .

ShortcutAction
Ctrl+RStart a reverse search or find an older match
Ctrl+SSearch forward, if terminal flow control is disabled
EscLeave the search with the match ready to edit
Ctrl+GCancel the search and restore the original input
EnterAccept and run the matching command

Use Esc to review a match before executing it.

Complete Words

Bash completes command names, paths, variables, and other words according to the current context.

ShortcutAction
TabComplete the word before the cursor
Tab twiceList alternatives when completion is ambiguous, with default settings
Alt+?List possible completions directly
Alt+/Complete a filename
Alt+$Complete a shell variable name

Completion of command-specific options, such as Git subcommands, depends on the completion functions installed on your system.

Control the Terminal and Jobs

Signals act on the foreground job. A program can handle or ignore some signals, so interrupting does not always terminate it.

ShortcutAction
Ctrl+CSend SIGINT to the foreground job; at the Bash prompt, cancel the input line
Ctrl+ZSuspend the foreground job with SIGTSTP
bg then EnterResume the suspended job in the background
fg then EnterBring the current job to the foreground
Ctrl+LClear the screen and redraw the current input line
Ctrl+D on empty inputSend EOF; at a Bash prompt, normally exit the shell

Ctrl+Z suspends rather than ends a job. Use the Job Control cheatsheet for job numbers, disown, and logout behavior.

Check Your Bindings

Run these commands in an interactive Bash shell. Custom bindings can override the defaults above.

Command or sequenceAction
set -o emacsEnable these Emacs-style bindings for this shell
set -o viSwitch to vi editing mode, which uses different bindings
bind -PList Readline functions and their current key bindings
bind -vShow Readline variable settings, including editing mode
Ctrl+X then Ctrl+RReload the Readline initialization file
stty -aShow terminal settings, including signal keys and flow control

Readline reads the file named by INPUTRC, or ~/.inputrc when that variable is unset. If that file cannot be read, it falls back to /etc/inputrc, so start a new ~/.inputrc with $include /etc/inputrc to keep your distribution’s bindings.

Terminal Caveats

The terminal can intercept a key before Bash receives it.

SymptomWhat to check
Alt shortcuts do not workUse Esc, then the other key; on macOS, you can also configure Option to send Meta
Ctrl+S pauses outputCtrl+Q resumes it when software flow control is enabled
You want forward history searchRun stty -ixon to disable software flow control for this terminal; stty ixon enables it again
Ctrl+D exits unexpectedlyIt deletes only when input is present; an empty line sends EOF. set -o ignoreeof prevents a single EOF from exiting Bash
Paste behaves differentlyCtrl+Y uses the kill ring; terminal clipboard paste is often Ctrl+Shift+V on Linux or Cmd+V on macOS

Use these references for scripting syntax, history settings, and the full list of Readline commands.

ReferenceCovers
Bash CheatsheetVariables, conditionals, loops, and shell scripting
history Command in LinuxHistory files, expansion, filtering, and settings
GNU Bash Readline CommandsOfficial shortcut definitions and function names
GNU Bash Readline ConfigurationInput files and custom key bindings