Bash keyboard shortcuts and shell syntax

The first tables list the default Emacs-mode key bindings of Readline, the line editor of Bash 5.3, taken from the Bash Reference Manual; the later ones hold text you type: history expansion, job control, redirection and common builtins. Programs such as ls or grep are not part of Bash and are left out, as is vi mode. Alt stands for the manual's Meta key: if it does nothing in your terminal, press Esc, then the key.

171 commands in 13 sections. Checked row by row against GNU Bash Reference Manual, Edition 5.3 for Bash 5.3 (last updated 18 May 2025) on . Edited by Jay.

Cursor movement 14

The manual prints bindings in Emacs notation: C-a is Control-A and M-b is Meta-B. Its Meta key is the one labelled Alt or Option on many keyboards, so M- bindings appear here as Alt, and M-C- bindings as Ctrl + Alt.

Where Alt does not act as Meta, press Esc and release it, then press the key: Esc followed by F does the same as Alt + F.

ShortcutWhat it does
Ctrl+AGo to start of lineThe Home key may run the same command, depending on the keyboard.
Ctrl+EGo to end of lineThe End key may run the same command, depending on the keyboard.
Ctrl+FForward one characterMoves right by one character; the Right arrow key may be bound to the same command.
Ctrl+BBack one characterMoves left by one character; the Left arrow key may be bound to the same command.
Alt+FForward one wordLands after the next word's last character; words are runs of letters and digits.
Alt+BBack one wordLands on the first character of this word or the one before; only letters and digits form words.
Ctrl+Alt+FForward one shell wordLike Alt + F, but words end only at unquoted shell metacharacters such as spaces, pipes and semicolons.
Ctrl+Alt+BBack one shell wordLike Alt + B, with word limits set by unquoted shell metacharacters instead of by letters and digits.
Ctrl+]Jump to next typed characterReads one character and moves forward to where it next appears; a negative argument looks backward.
Ctrl+Alt+]Jump back to typed characterReads one character and moves to the nearest place it appears earlier in the line.
Ctrl+@Set markSaves the cursor position as the mark; the text between mark and cursor is called the region.
Ctrl+XthenCtrl+XSwap cursor and markThe cursor jumps to the saved mark, and the mark moves to where the cursor was.
Ctrl+LClear screenThe line being edited is redrawn on the top row; with a numeric argument only that line is refreshed.
Ctrl+Alt+LClear screen and scrollbackAlso erases the terminal's scrollback buffer where the terminal allows it, then redraws the line on the top row.

Editing text 13

Backspace stands for the key the manual calls DEL or Rubout. Depending on configuration, the DEL key may instead delete the character under the cursor, as Ctrl + D does.

ShortcutWhat it does
Ctrl+DDelete character at cursorThe Delete key may run the same command, depending on the keyboard.
Ctrl+DSend end of fileOn an empty line the character is read as end of input; Bash then exits unless IGNOREEOF is set.
BackspaceDelete previous characterThe manual names this key DEL or Rubout; with a numeric argument the removed characters go to the kill ring.
Ctrl+QorCtrl+VInsert next character literallyThe next key is added to the line as typed, which is how a control character gets entered.
Ctrl+TTranspose charactersSwaps the character before the cursor with the one under it; at the end of a line, the last two.
Alt+TTranspose wordsMoves the word before the cursor past the word after it; at the end of a line it swaps the final two words.
Ctrl+Alt+TTranspose shell wordsSame swap as Alt + T, but with the word limits of the shell-word movement commands.
Alt+UUppercase wordApplies to the current or following word; a negative argument changes the previous word and leaves the cursor in place.
Alt+LLowercase wordConverts the current or following word to lower case; with a negative argument, the word before the cursor.
Alt+CCapitalize wordWorks on the current or following word, or on the previous one when given a negative argument.
Ctrl+_orCtrl+XthenCtrl+UUndo last editEach press takes back one more change; undo history is kept per line, back to the empty line.
Alt+RRevert lineTakes back every change made to the line in one step, returning it to its initial state.
Alt+#Comment out the linePuts the comment-begin string, # by default, in front of the line and accepts it as a shell comment.

Killing and yanking 9

ShortcutWhat it does
Ctrl+KKill to end of lineCuts from the cursor to the line's end onto the kill ring; a negative argument kills toward the start instead.
Ctrl+UKill to start of lineCuts everything in front of the cursor; like any kill, the text can be yanked back.
Ctrl+XthenBackspaceKill backward to line startWritten C-x Rubout in the manual; a negative argument makes it kill forward to the end instead.
Alt+DKill word after cursorKills up to where the current word stops or, between words, the following one; word limits match Alt + F.
Alt+BackspaceKill word before cursorWritten M-DEL in the manual; word limits are those of Alt + B, so only letters and digits form the word.
Ctrl+Alt+DKill shell word after cursorKills forward over one shell word, using the same word limits as Ctrl + Alt + F.
Ctrl+WKill word back to whitespaceOnly white space counts as a word limit here, unlike Alt + Backspace; the text is saved on the kill ring.
Ctrl+YYank killed textInserts the most recently killed text at the cursor; Alt + Y then swaps in earlier kills.
Alt+YYank earlier killRotates the kill ring and inserts its new top; works only right after Ctrl + Y or another Alt + Y.

History 12

Arrow keys, Home, End and Delete have no rows of their own: the manual only says the matching commands may also be bound to them on some keyboards.

ShortcutWhat it does
EnterAccept the lineRuns the whole line wherever the cursor is and, if it is not empty, adds it to the history list.
Ctrl+PPrevious commandSteps back through the history list; the Up arrow key may be bound to the same command.
Ctrl+NNext commandSteps forward through the history list; the Down arrow key may be bound to the same command.
Alt+<First history entryJumps to the oldest line that the history list holds.
Alt+>End of historyLeaves the stored entries and returns to the new line you were entering.
Ctrl+RSearch history backwardIncremental: each typed character shows the newest matching entry, and pressing it again finds older matches.
Ctrl+SSearch history forwardIncremental search toward newer entries, the opposite direction of Ctrl + R.
Alt+PNon-incremental search backwardReads the whole search string first, then finds an older history line containing it anywhere.
Alt+NNon-incremental search forwardReads the whole search string first, then looks toward newer history lines for it.
Ctrl+Alt+YInsert first argument of last commandWith a numeric argument N it inserts word N of that command instead; words count from 0.
Alt+.orAlt+_Insert last argument of last commandRepeat it to step back through the history, inserting the final word of each earlier line in turn.
Ctrl+ORun line and fetch nextExecutes the current line, then brings up the history line that follows it for editing.

Completion 16

ShortcutWhat it does
TabComplete wordBash tries programmable completion first, then variable, username, hostname and command completion, and finally filenames.
Alt+?List possible completionsShows the candidates for the text before the cursor; Alt + * inserts them all instead.
Alt+*Insert all completionsPuts every completion Alt + ? would have listed into the line, separated by spaces.
Alt+/Complete as filenameSkips the other completion types and goes straight to file names.
Ctrl+Xthen/List filename completions
Alt+~Complete as usernameTreats the text before the cursor as a user name.
Ctrl+Xthen~List username completions
Alt+$Complete as variableTreats the text before the cursor as the name of a shell variable.
Ctrl+Xthen$List variable completions
Alt+@Complete as hostnameTreats the text before the cursor as a host name.
Ctrl+Xthen@List hostname completions
Alt+!Complete as command nameCandidates come from aliases, then reserved words, functions, builtins and executable files.
Ctrl+Xthen!List command completions
Alt+TabComplete from historyLooks for completion matches among the entries of the history list.
Alt+{Complete into bracesInserts all matching filenames as one brace expression, which the shell then expands to the full list.
Alt+GComplete glob patternReads the word as a pattern with an implied trailing asterisk and offers the matching file names as completions.

Expanding and running the line 8

ShortcutWhat it does
Ctrl+Xthen*Expand glob patternReplaces the pattern before the cursor with the list of file names it matches.
Ctrl+XthenGList glob expansionsShows what Ctrl + X, * would insert, then redisplays the line.
Ctrl+Alt+EExpand lineApplies alias and history expansion plus the shell word expansions to the text of the line.
Alt+^Expand history referencesReplaces history expansions such as !! or !$ in the current line with the text they stand for.
Alt+&Expand tildeApplies only to the word the cursor is on.
Ctrl+XthenSCorrect spelling of wordReads the current word as a directory or file name and corrects it the way the cdspell option does.
Ctrl+XthenCtrl+EEdit line in editorOpens the line in $VISUAL, $EDITOR or emacs, whichever is found first, and runs what you save.
Ctrl+XthenCtrl+VShow Bash versionPrints the version details of the Bash instance you are typing in.

Arguments, macros and editor control 9

ShortcutWhat it does
Alt+1Start numeric argumentAlt with any digit, M-0 to M-9 in the manual, starts or extends a count for the next command.
Alt+-Negative argumentStarts a negative numeric argument, which makes many commands act in the opposite direction.
Ctrl+Xthen(Start recording macroFrom here on the typed characters are saved into the current keyboard macro.
Ctrl+Xthen)Stop recording macroEnds the recording and stores the macro definition.
Ctrl+XthenERun last macroReplays the characters of the most recently defined macro as if you had typed them.
Alt+XRun command by namePrompts for the name of a bindable Readline command and runs it, passing along any numeric argument.
EscMeta prefix for next keyEsc followed by F does the same as Alt + F, for terminals or keyboards without a working Meta key.
Ctrl+GAbort current commandCancels the editing command in progress and rings the bell; during an incremental search it restores the original line.
Ctrl+XthenCtrl+RReload inputrcReads the inputrc file again and applies the key bindings and variable settings found there.

History expansion 26

ShortcutWhat it does
!!Repeat previous commandRefers to the previous history entry; the manual gives !-1 as its synonym.
!NHistory entry by numberN is the number that the history builtin prints in front of the entry.
!-NEntry N commands backCounts backward from the current position, so !-2 is the command before the previous one.
!STRINGLatest command starting with stringFinds the newest earlier entry whose text begins with the given characters.
!?STRING?Latest command containing stringThe closing ? may be left out when the string is the last thing on the line.
^STRING1^STRING2^Quick substitutionReruns the previous command with STRING1 changed to STRING2; it must start the line.
!#Current line so farExpands to everything typed on the current command line before this point.
!$Last argument of previous commandShort for !!:$, the final word of the line before, which is usually its last argument.
!^First argument of previous commandWord 1 of the line before; word 0 is the command name itself.
!*All arguments of previous commandEvery word except word 0, the same range as 1-$; empty if the command had no arguments.
:pPrint without runningAdded after an event, this modifier shows the expanded command instead of executing it.
:s/OLD/NEW/Substitute in recalled commandChanges the first OLD in the event line to NEW; another character can replace the slash as delimiter.
:gs/OLD/NEW/Substitute everywhereThe g prefix makes the substitution apply across the whole event line, not just to the first match.
:hKeep directory partStrips the last pathname component from the selected word, so only the head remains.
:tKeep file name partDrops every directory in front of the name, so only the tail remains.
:rRemove file suffixCuts a trailing .suffix from the selected word.
historyShow history listPrints the remembered commands with their numbers; history N limits the output to the newest N entries.
history -cClear history listEmpties the list kept by the running shell; other options can then refill it.
history -d OFFSETDelete a history entryOFFSET is the number displayed next to the entry; a negative value counts back from the end.
history -aAppend session to history fileWrites the lines entered in this session that the history file does not contain yet.
history -wWrite history fileSaves the current list to the history file, replacing what the file held.
fcEdit and rerun previous commandOpens the command in the editor named by FCEDIT, then EDITOR, then vi, and executes the saved result.
fc -lList recent commandsPrints commands with their numbers instead of editing; the default range is the last 16.
fc -sRe-execute a commandRuns the selected command again without an editor; PAT=REP first replaces every PAT in it with REP.
set +HTurn off history expansionStops ! from being treated specially in an interactive shell; set -H turns the feature back on.
shopt -s histverifyReview expansions before runningWith Readline in use, an expanded line is loaded back into the edit line for checking instead of running at once.

Job control 20

ShortcutWhat it does
Ctrl+ZSuspend foreground jobStops the running process at once and hands the terminal back to Bash; pending output and typeahead are discarded.
Ctrl+YDelayed suspendThe process keeps running until it next asks the terminal for input, then stops.
Ctrl+CInterrupt foreground commandUsually generates SIGINT, the signal users mean for the command that is running in the foreground.
COMMAND &Run command in backgroundThe shell starts it asynchronously in a subshell and returns to the prompt without waiting for it.
jobsList active jobsEach job is shown with its number in brackets; + marks the current job and - the previous one.
jobs -lList jobs with process IDsAdds the process ID of each job to the normal listing.
fg JOBSPECBring job to foregroundWithout a jobspec it resumes the current job; a bare jobspec such as %1 is a synonym for fg %1.
bg JOBSPECResume job in backgroundA stopped job continues running as though launched with &; without a jobspec, the current job is used.
%NJob by numberA jobspec: pass it to fg, bg, kill, wait or disown to name job number N.
%% / %+Current jobThe job most recently started in the background or stopped; a lone % means the same.
%-Previous jobThe job that was current until another job took its place.
%STRINGJob by name prefixSelects the job whose command line begins with these characters; Bash reports an error if several match.
%?STRINGJob by name substringSelects the job whose command line contains the string anywhere.
kill IDSend SIGTERM to job or processID is a process ID or a jobspec such as %1; SIGTERM is what gets sent when no signal is named.
kill -s SIGSPEC IDSend a chosen signalThe signal is given by name, where the SIG prefix is optional and case is ignored, or by number.
kill -lList signal namesGiven an exit status as argument, it names the signal that ended that process.
waitWait for background jobsWith no arguments it waits for every running background job; with an ID, for that job or process only.
disownRemove job from job tableGiven no ID it acts on the current job, which then no longer shows up in the list of jobs.
disown -hKeep job after hangupLeaves the job in the table but marks it so the shell does not pass SIGHUP on to it.
suspendSuspend the shellStops this shell until it gets SIGCONT; a login shell refuses unless -f is given.

Pipelines and redirection 14

ShortcutWhat it does
COMMAND1 | COMMAND2Pipe output to next commandConnects the standard output of the first command to the standard input of the second.
COMMAND1 |& COMMAND2Pipe output and errorsSends standard error through the pipe as well; shorthand for 2>&1 followed by a pipe.
COMMAND1 && COMMAND2Run next only on successThe second command is skipped unless the first one exits with status zero.
COMMAND1 || COMMAND2Run next only on failureThe second command runs only when the first one exits with a status other than zero.
COMMAND ; COMMANDRun commands in sequenceEach command starts only after the one before it has finished; the list's status is that of its final command.
> FILERedirect output to fileCreates the file if needed and otherwise empties it before writing.
>> FILEAppend output to fileAdds to the end of the file instead of overwriting it, creating the file when it is missing.
< FILERead input from fileOpens the file for reading on standard input, file descriptor 0, unless a descriptor number precedes the operator.
2>&1Send errors to standard outputOrder matters: after > FILE it sends both streams to the file, before it only standard output goes there.
&> FILERedirect output and errorsSends both streams to the file; the manual prefers this form over >& FILE.
&>> FILEAppend output and errorsWorks like >> FILE followed by 2>&1, adding both streams to the end of the file.
>| FILEOverwrite despite noclobberForces the redirection even when the noclobber option would refuse to overwrite an existing regular file.
<< WORDHere documentThe lines that follow become the command's standard input, up to a line holding only the delimiter.
<<< WORDHere stringSupplies the expanded word, plus a final newline, as the command's standard input.

Directories 10

ShortcutWhat it does
cd DIRECTORYChange directoryA name without a leading slash is also looked up in the directories listed in CDPATH, when that variable exists.
cdGo to home directoryWith no argument, the target is whatever the HOME variable holds.
cd -Return to previous directoryThe hyphen is converted to $OLDPWD, and the new directory name is printed after the change.
pwdPrint working directoryPrints the absolute path; with -P the path contains no symbolic links.
pushd DIRPush directory onto stackMakes DIR the current directory and puts it first on the stack, so popd can return to the old one.
pushdSwap top two directoriesWith no arguments it exchanges the two newest stack entries, which also switches the current directory.
popdPop directory stackRemoves the top entry and changes to the directory that becomes the new top.
dirs -vList directory stackShows the remembered directories one per line, numbered by stack position.
~Home directoryAt the start of a word, an unquoted tilde alone expands to the HOME directory.
~-Previous directoryExpands to the value of OLDPWD when that variable is set.

Shell builtins and settings 11

ShortcutWhat it does
set -o viSwitch to vi editing modeEach line starts in insertion mode; Esc enters command mode with the standard vi movement keys.
set -o emacsSwitch to emacs editing modeReturns to the default editing mode, the one whose key bindings this page lists.
bind -PList key bindingsPrints each Readline command with the keys currently bound to it in your own shell.
bind -pList bindings in inputrc formatTerser output than bind -P, in a form that can be pasted into an inputrc file.
aliasList or define aliasesAlone it prints the defined aliases in reusable form; with NAME=VALUE arguments it defines them.
unalias NAMERemove an aliasWith -a instead of a name, every alias is removed.
type NAMEShow how a name resolvesTells whether the name would run as an alias, a reserved word, a function, a builtin or a file on disk.
help PATTERNHelp for a builtinPrints detailed help on the builtins matching the pattern; with no argument it lists them all.
export NAMEExport variable to environmentMarks the variable so that commands run afterwards receive it; NAME=VALUE assigns a value at the same time.
source FILENAMERun script in current shellReads and executes the file's commands in the shell you are in; a single dot is the same command.
exitExit the shellReturns the status of the last command executed unless a number is given; a trap on EXIT runs first.

Special parameters 9

ShortcutWhat it does
$?Exit status of last commandZero means the most recent command succeeded; any other value reports a failure.
$$Shell process IDA subshell reports its parent shell's ID here rather than its own.
$!PID of last background jobRefers to the job most recently put in the background with & or the bg builtin.
$#Number of positional parametersA decimal count of the arguments passed to the script or function.
$@All arguments as separate wordsWritten "$@" it expands to "$1" "$2" and so on, one word per positional parameter.
$*All arguments as one wordWritten "$*" it joins the positional parameters into a single word, using the first IFS character as separator.
$0Name of shell or scriptWhen Bash runs a file of commands this is that file's name; otherwise the name used to invoke Bash.
$_Last argument, after expansionHolds the final argument of the previous simple command run in the foreground.
$-Current option flagsShows the single-letter options in effect, whether given at invocation, through set or turned on by the shell.

Notes

Two kinds of “shortcuts”

This page holds two different things. The tables from Cursor movement to Arguments, macros and editor control are true keyboard shortcuts: the default bindings of Readline, the library Bash uses to read a command line, in its Emacs mode. The tables after them — history expansion, job control, redirection, builtins, special parameters — are text you type and Bash interprets, apart from the terminal keys listed under job control. Programs such as ls, grep or ps are separate tools with their own manuals, not part of Bash, so they are not listed here. Readline is used by several other programs as well, so the editing keys carry over to them. To see the bindings of your own shell, run bind -P, or bind -p for output in inputrc format.

Emacs-style editing

Readline's default commands resemble those of Emacs: Ctrl + A/E jump to line start and end, Alt + B/F hop by word, and the deletion keys cut into a kill ring you can paste back from with Ctrl + Y. The manual calls it a loose convention that control keystrokes work on characters and meta keystrokes on words. The workhorse combo: mistyped a long command's beginning? Ctrl + U wipes to the start; changed your mind? Ctrl + Y brings it back. Ctrl + T swaps the character before the cursor with the one under it — the instant fix for sl. The manual writes these keys as C-a and M-b; Meta is the key labelled Alt or Option, and where it does nothing you press Esc first, then the letter. Prefer vi keys? set -o vi switches the whole editing model.

History is a database, not a scrollback

Arrow-key archaeology is the slow way. Ctrl + R starts an incremental reverse search — type any fragment of a past command and press Ctrl + R again to walk further back through matches. The expansion words are just as fast: !! reruns the last command (the canonical sudo !! after a permission error), and !$ reuses its last argument — mkdir deep/path then cd !$. If running an expansion unseen feels risky, shopt -s histverify loads the expanded line into the editor first. One trap: Ctrl + S searches forward but many terminals treat it as flow-control freeze; stty -ixon frees it (and Ctrl + Q unfreezes). That is terminal behaviour, outside the Bash manual.

Questions

What does Ctrl+R do in bash?

Incremental reverse history search: start typing any part of a previous command and readline finds it; press Ctrl+R again to step to older matches, Enter to run, Esc to edit first. Ctrl+G cancels the search and restores the line you had.

How do I delete the whole command line in bash quickly?

Ctrl+U deletes from the cursor to the start of the line (with the cursor at the end, that's everything). The cut text goes to the kill ring — Ctrl+Y pastes it back.

Why does Ctrl+S freeze my terminal instead of searching?

That's XON/XOFF flow control at the terminal level, not Bash. Press Ctrl+Q to unfreeze, and add `stty -ixon` to your shell profile to reclaim Ctrl+S for forward history search.

What do C-a and M-b mean in the Bash manual?

It is Emacs notation. C-a means hold Ctrl and press A. M-b is Meta-B: the Meta key is labelled Alt or Option on many keyboards, and pressing Esc first, then B, has the same effect when Alt does not work. This page writes them as Ctrl + A and Alt + B.

Do bash editing shortcuts work in other tools?

In programs built on the same library, yes. The keys belong to GNU Readline, which the Bash manual describes as used by several different programs; its sample init file names FTP and GDB next to Bash. A tool that uses another line editor may copy only some of them.

What is sudo !! and why does everyone use it?

!! expands to the previous command, so after a “permission denied” you type sudo !! to rerun it with privileges instead of retyping.

How do I switch bash to vi-style editing?

Run `set -o vi` (or put it in ~/.bashrc). Esc then h/j/k/l, w/b, and the rest of vi's editing grammar replace the Emacs-style defaults on this page; `set -o emacs` switches back.

Sources and checks

Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.

25 rows from the earlier version of this page were removed in that check: duplicates, and bindings the documentation does not list or lists differently.

Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.