LLI Wiki — My Digital Knowledge Base

Bash keyboard shortcuts and command history

Bash keyboard shortcuts for editing the command line, searching the history, managing processes and using ! history expansion.

The Bash keyboard shortcuts that save the most time in daily use: editing the line, moving the cursor, searching the history, controlling the screen and processes.

Edit the command in an editor

Shortcut Effect
Ctrl+X then Ctrl+E Opens the current command line in the editor set by $EDITOR

To set the editor:

export EDITOR=vim

Control the screen

Shortcut Effect
Ctrl+L Clears the screen (same effect as clear)
Ctrl+S Pauses the output of a long command
Ctrl+Q Resumes the output after Ctrl+S

Move the cursor

Shortcut Effect
Ctrl+A or Home Start of the line
Ctrl+E or End End of the line
Ctrl+B or Left arrow One character left
Ctrl+F or Right arrow One character right
Ctrl+Left arrow, Alt+B or Esc then B One word left
Ctrl+Right arrow, Alt+F or Esc then F One word right

Browse and search the history

Shortcut Effect
Up arrow or Ctrl+P Previous command (press again to go further back)
Down arrow or Ctrl+N Next command
Ctrl+R Reverse search: type a few characters that are unique to the command
Ctrl+S Forward search (see the remarks)
Ctrl+G Cancels a reverse or forward search

Delete text

Shortcut Effect
Ctrl+D or Delete Deletes the character under the cursor
Ctrl+K Deletes from the cursor to the end of the line
Ctrl+X then Backspace Deletes from the cursor to the start of the line

Transpose text or change case

Shortcut Effect
Ctrl+T Swaps the character before the cursor with the one under it
Esc then T Swaps the two words before (or under) the cursor
Esc then U Uppercases from the cursor to the end of the word
Esc then L Lowercases from the cursor to the end of the word
Esc then C Uppercases the letter under the cursor (or the first letter of the next word)

Manage processes

Shortcut Effect
Ctrl+Z Suspends the foreground process (SIGTSTP); resume it with fg, or fg %1, fg %2...
Ctrl+C Interrupts the foreground process (SIGINT); the process may handle or ignore it
Ctrl+D Exits the shell (same as exit)

History expansion with !

Command Effect
!! Runs the last command
!top Runs the most recent command starting with top
!top:p Prints the command that !top would run, and adds it as the latest history entry
!$ Last word of the previous command (same as Alt+.)
!$:p Prints the word that !$ would substitute
!* All arguments of the previous command
!*:p Prints those arguments without running them

To list the history, use fc -l.

Remarks

Mastodon LLIMastodon SocialFosstodon