Ctrl K

Linux Shell Line Editing Shortcuts

Common Bash and readline shortcuts for deleting, undoing, and moving through command-line text.

Common terminal line editing shortcuts for Bash and other readline-style shells. These shortcuts help edit long commands without reaching for the mouse or repeatedly pressing Backspace.

Delete text while editing a command

Use these shortcuts while typing or editing a command in the terminal.

ActionShortcut
Delete previous wordCtrl + W
Delete next wordAlt + D
Delete from cursor to start of lineCtrl + U
Delete from cursor to end of lineCtrl + K
Undo last editCtrl + _ or Ctrl + X then Ctrl + U

Example

Given this command:

python manage.py runserver --settings config.local
  • If the cursor is after local, pressing Ctrl + W deletes config.local.
  • Pressing Ctrl + W again deletes --settings.

Word boundary behavior

Ctrl + W deletes based on shell/readline word boundaries. Paths and punctuation can behave differently depending on terminal and readline settings.

cd /home/user/projects/myapp

In a path like this, Ctrl + W may delete the whole path or delete chunks of it depending on the active shell/readline behavior.

Move word by word

Use these shortcuts to move through long commands quickly.

ActionShortcut
Move back one wordAlt + B
Move forward one wordAlt + F
Delete previous wordCtrl + W
Delete next wordAlt + D

Compact keyboard note

  • On compact keyboards, Alt may also be treated as Meta.
  • In most terminals, normal Alt + B, Alt + F, and Alt + D work directly.