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.
| Shortcut | What it does |
|---|---|
| Ctrl+A | Go to start of lineThe Home key may run the same command, depending on the keyboard. |
| Ctrl+E | Go to end of lineThe End key may run the same command, depending on the keyboard. |
| Ctrl+F | Forward one characterMoves right by one character; the Right arrow key may be bound to the same command. |
| Ctrl+B | Back one characterMoves left by one character; the Left arrow key may be bound to the same command. |
| Alt+F | Forward one wordLands after the next word's last character; words are runs of letters and digits. |
| Alt+B | Back one wordLands on the first character of this word or the one before; only letters and digits form words. |
| Ctrl+Alt+F | Forward one shell wordLike Alt + F, but words end only at unquoted shell metacharacters such as spaces, pipes and semicolons. |
| Ctrl+Alt+B | Back 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+X | Swap cursor and markThe cursor jumps to the saved mark, and the mark moves to where the cursor was. |
| Ctrl+L | Clear screenThe line being edited is redrawn on the top row; with a numeric argument only that line is refreshed. |
| Ctrl+Alt+L | Clear 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.
| Shortcut | What it does |
|---|---|
| Ctrl+D | Delete character at cursorThe Delete key may run the same command, depending on the keyboard. |
| Ctrl+D | Send end of fileOn an empty line the character is read as end of input; Bash then exits unless IGNOREEOF is set. |
| Backspace | Delete previous characterThe manual names this key DEL or Rubout; with a numeric argument the removed characters go to the kill ring. |
| Ctrl+QorCtrl+V | Insert next character literallyThe next key is added to the line as typed, which is how a control character gets entered. |
| Ctrl+T | Transpose charactersSwaps the character before the cursor with the one under it; at the end of a line, the last two. |
| Alt+T | Transpose 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+T | Transpose shell wordsSame swap as Alt + T, but with the word limits of the shell-word movement commands. |
| Alt+U | Uppercase wordApplies to the current or following word; a negative argument changes the previous word and leaves the cursor in place. |
| Alt+L | Lowercase wordConverts the current or following word to lower case; with a negative argument, the word before the cursor. |
| Alt+C | Capitalize wordWorks on the current or following word, or on the previous one when given a negative argument. |
| Ctrl+_orCtrl+XthenCtrl+U | Undo last editEach press takes back one more change; undo history is kept per line, back to the empty line. |
| Alt+R | Revert 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
| Shortcut | What it does |
|---|---|
| Ctrl+K | Kill 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+U | Kill to start of lineCuts everything in front of the cursor; like any kill, the text can be yanked back. |
| Ctrl+XthenBackspace | Kill backward to line startWritten C-x Rubout in the manual; a negative argument makes it kill forward to the end instead. |
| Alt+D | Kill word after cursorKills up to where the current word stops or, between words, the following one; word limits match Alt + F. |
| Alt+Backspace | Kill 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+D | Kill shell word after cursorKills forward over one shell word, using the same word limits as Ctrl + Alt + F. |
| Ctrl+W | Kill word back to whitespaceOnly white space counts as a word limit here, unlike Alt + Backspace; the text is saved on the kill ring. |
| Ctrl+Y | Yank killed textInserts the most recently killed text at the cursor; Alt + Y then swaps in earlier kills. |
| Alt+Y | Yank 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.
| Shortcut | What it does |
|---|---|
| Enter | Accept the lineRuns the whole line wherever the cursor is and, if it is not empty, adds it to the history list. |
| Ctrl+P | Previous commandSteps back through the history list; the Up arrow key may be bound to the same command. |
| Ctrl+N | Next 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+R | Search history backwardIncremental: each typed character shows the newest matching entry, and pressing it again finds older matches. |
| Ctrl+S | Search history forwardIncremental search toward newer entries, the opposite direction of Ctrl + R. |
| Alt+P | Non-incremental search backwardReads the whole search string first, then finds an older history line containing it anywhere. |
| Alt+N | Non-incremental search forwardReads the whole search string first, then looks toward newer history lines for it. |
| Ctrl+Alt+Y | Insert 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+O | Run line and fetch nextExecutes the current line, then brings up the history line that follows it for editing. |
Completion 16
| Shortcut | What it does |
|---|---|
| Tab | Complete 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+Tab | Complete 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+G | Complete 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
| Shortcut | What it does |
|---|---|
| Ctrl+Xthen* | Expand glob patternReplaces the pattern before the cursor with the list of file names it matches. |
| Ctrl+XthenG | List glob expansionsShows what Ctrl + X, * would insert, then redisplays the line. |
| Ctrl+Alt+E | Expand 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+XthenS | Correct spelling of wordReads the current word as a directory or file name and corrects it the way the cdspell option does. |
| Ctrl+XthenCtrl+E | Edit line in editorOpens the line in $VISUAL, $EDITOR or emacs, whichever is found first, and runs what you save. |
| Ctrl+XthenCtrl+V | Show Bash versionPrints the version details of the Bash instance you are typing in. |
Arguments, macros and editor control 9
| Shortcut | What it does |
|---|---|
| Alt+1 | Start 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+XthenE | Run last macroReplays the characters of the most recently defined macro as if you had typed them. |
| Alt+X | Run command by namePrompts for the name of a bindable Readline command and runs it, passing along any numeric argument. |
| Esc | Meta prefix for next keyEsc followed by F does the same as Alt + F, for terminals or keyboards without a working Meta key. |
| Ctrl+G | Abort current commandCancels the editing command in progress and rings the bell; during an incremental search it restores the original line. |
| Ctrl+XthenCtrl+R | Reload inputrcReads the inputrc file again and applies the key bindings and variable settings found there. |
History expansion 26
| Shortcut | What it does |
|---|---|
!! | Repeat previous commandRefers to the previous history entry; the manual gives !-1 as its synonym. |
!N | History entry by numberN is the number that the history builtin prints in front of the entry. |
!-N | Entry N commands backCounts backward from the current position, so !-2 is the command before the previous one. |
!STRING | Latest 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. |
:p | Print 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. |
:h | Keep directory partStrips the last pathname component from the selected word, so only the head remains. |
:t | Keep file name partDrops every directory in front of the name, so only the tail remains. |
:r | Remove file suffixCuts a trailing .suffix from the selected word. |
history | Show history listPrints the remembered commands with their numbers; history N limits the output to the newest N entries. |
history -c | Clear history listEmpties the list kept by the running shell; other options can then refill it. |
history -d OFFSET | Delete a history entryOFFSET is the number displayed next to the entry; a negative value counts back from the end. |
history -a | Append session to history fileWrites the lines entered in this session that the history file does not contain yet. |
history -w | Write history fileSaves the current list to the history file, replacing what the file held. |
fc | Edit and rerun previous commandOpens the command in the editor named by FCEDIT, then EDITOR, then vi, and executes the saved result. |
fc -l | List recent commandsPrints commands with their numbers instead of editing; the default range is the last 16. |
fc -s | Re-execute a commandRuns the selected command again without an editor; PAT=REP first replaces every PAT in it with REP. |
set +H | Turn off history expansionStops ! from being treated specially in an interactive shell; set -H turns the feature back on. |
shopt -s histverify | Review 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
| Shortcut | What it does |
|---|---|
| Ctrl+Z | Suspend foreground jobStops the running process at once and hands the terminal back to Bash; pending output and typeahead are discarded. |
| Ctrl+Y | Delayed suspendThe process keeps running until it next asks the terminal for input, then stops. |
| Ctrl+C | Interrupt 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. |
jobs | List active jobsEach job is shown with its number in brackets; + marks the current job and - the previous one. |
jobs -l | List jobs with process IDsAdds the process ID of each job to the normal listing. |
fg JOBSPEC | Bring job to foregroundWithout a jobspec it resumes the current job; a bare jobspec such as %1 is a synonym for fg %1. |
bg JOBSPEC | Resume job in backgroundA stopped job continues running as though launched with &; without a jobspec, the current job is used. |
%N | Job 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. |
%STRING | Job by name prefixSelects the job whose command line begins with these characters; Bash reports an error if several match. |
%?STRING | Job by name substringSelects the job whose command line contains the string anywhere. |
kill ID | Send 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 ID | Send a chosen signalThe signal is given by name, where the SIG prefix is optional and case is ignored, or by number. |
kill -l | List signal namesGiven an exit status as argument, it names the signal that ended that process. |
wait | Wait for background jobsWith no arguments it waits for every running background job; with an ID, for that job or process only. |
disown | Remove job from job tableGiven no ID it acts on the current job, which then no longer shows up in the list of jobs. |
disown -h | Keep job after hangupLeaves the job in the table but marks it so the shell does not pass SIGHUP on to it. |
suspend | Suspend the shellStops this shell until it gets SIGCONT; a login shell refuses unless -f is given. |
Pipelines and redirection 14
| Shortcut | What it does |
|---|---|
COMMAND1 | COMMAND2 | Pipe output to next commandConnects the standard output of the first command to the standard input of the second. |
COMMAND1 |& COMMAND2 | Pipe output and errorsSends standard error through the pipe as well; shorthand for 2>&1 followed by a pipe. |
COMMAND1 && COMMAND2 | Run next only on successThe second command is skipped unless the first one exits with status zero. |
COMMAND1 || COMMAND2 | Run next only on failureThe second command runs only when the first one exits with a status other than zero. |
COMMAND ; COMMAND | Run commands in sequenceEach command starts only after the one before it has finished; the list's status is that of its final command. |
> FILE | Redirect output to fileCreates the file if needed and otherwise empties it before writing. |
>> FILE | Append output to fileAdds to the end of the file instead of overwriting it, creating the file when it is missing. |
< FILE | Read input from fileOpens the file for reading on standard input, file descriptor 0, unless a descriptor number precedes the operator. |
2>&1 | Send errors to standard outputOrder matters: after > FILE it sends both streams to the file, before it only standard output goes there. |
&> FILE | Redirect output and errorsSends both streams to the file; the manual prefers this form over >& FILE. |
&>> FILE | Append output and errorsWorks like >> FILE followed by 2>&1, adding both streams to the end of the file. |
>| FILE | Overwrite despite noclobberForces the redirection even when the noclobber option would refuse to overwrite an existing regular file. |
<< WORD | Here documentThe lines that follow become the command's standard input, up to a line holding only the delimiter. |
<<< WORD | Here stringSupplies the expanded word, plus a final newline, as the command's standard input. |
Directories 10
| Shortcut | What it does |
|---|---|
cd DIRECTORY | Change directoryA name without a leading slash is also looked up in the directories listed in CDPATH, when that variable exists. |
cd | Go 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. |
pwd | Print working directoryPrints the absolute path; with -P the path contains no symbolic links. |
pushd DIR | Push directory onto stackMakes DIR the current directory and puts it first on the stack, so popd can return to the old one. |
pushd | Swap top two directoriesWith no arguments it exchanges the two newest stack entries, which also switches the current directory. |
popd | Pop directory stackRemoves the top entry and changes to the directory that becomes the new top. |
dirs -v | List 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
| Shortcut | What it does |
|---|---|
set -o vi | Switch to vi editing modeEach line starts in insertion mode; Esc enters command mode with the standard vi movement keys. |
set -o emacs | Switch to emacs editing modeReturns to the default editing mode, the one whose key bindings this page lists. |
bind -P | List key bindingsPrints each Readline command with the keys currently bound to it in your own shell. |
bind -p | List bindings in inputrc formatTerser output than bind -P, in a form that can be pasted into an inputrc file. |
alias | List or define aliasesAlone it prints the defined aliases in reusable form; with NAME=VALUE arguments it defines them. |
unalias NAME | Remove an aliasWith -a instead of a name, every alias is removed. |
type NAME | Show 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 PATTERN | Help for a builtinPrints detailed help on the builtins matching the pattern; with no argument it lists them all. |
export NAME | Export variable to environmentMarks the variable so that commands run afterwards receive it; NAME=VALUE assigns a value at the same time. |
source FILENAME | Run script in current shellReads and executes the file's commands in the shell you are in; a single dot is the same command. |
exit | Exit the shellReturns the status of the last command executed unless a number is given; a trap on EXIT runs first. |
Special parameters 9
| Shortcut | What 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. |
$0 | Name 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. |
No row on this page matches that filter.
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
- GNU Bash Reference Manual, Edition 5.3 for Bash 5.3 (last updated 18 May 2025) — single-page copy on the Bash maintainer's site Bindable Readline Commands (default emacs-mode key bindings), History Expansion, Job Control, Redirections, shell builtins and special parameters
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.