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.
| Action | Shortcut |
|---|---|
| Delete previous word | Ctrl + W |
| Delete next word | Alt + D |
| Delete from cursor to start of line | Ctrl + U |
| Delete from cursor to end of line | Ctrl + K |
| Undo last edit | Ctrl + _ 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/myappIn 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.
| Action | Shortcut |
|---|---|
| Move back one word | Alt + B |
| Move forward one word | Alt + F |
| Delete previous word | Ctrl + W |
| Delete next word | Alt + 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.