| Autocompletion in Bash |
| History Search and Expansion |
| Recording Terminal Sessions with script |
1. Editing Commands with Readline
Bash uses the Readline library, which supports rich editing, navigation, and clipboard operations directly from the terminal.
Cursor Movement Keys
Key | Action |
Ctrl+A | Move to beginning of line |
Ctrl+E | Move to end of line |
Ctrl+F / → | Forward one character |
Ctrl+B / ← | Backward one character |
Alt+F | Forward one word |
Alt+B | Backward one word |
Ctrl+L | Clear screen |
Text Editing Shortcuts
Key | Action |
Ctrl+D | Delete current character |
Ctrl+T | Transpose character with previous |
Alt+T | Transpose current and previous word |
Alt+L | Lowercase to end of word |
Alt+U | Uppercase to end of word |
2. Cutting and Pasting with Kill & Yank
Text is cut into a buffer (kill-ring) and pasted using:
Key | Action |
Ctrl+K | Kill to end of line |
Ctrl+U | Kill to beginning of line |
Alt+D | Kill to end of word |
Alt+Backspace | Kill to beginning of word |
Ctrl+Y | Yank (paste) last killed text |
3. Autocompletion with Tab
Pressing TAB
completes filenames, commands, directories, and more:
ls l[TAB] → ls-output.txt
ls Do[TAB] → Documents
Supported Completions:
- File/directory paths
- Environment variables like
$HO[TAB]
- Usernames
~user
- System commands
- Hosts from
/etc/hosts
Additional Keys:
Key | Action |
Alt + ? | List all completions |
Alt + * | Insert all matching items |
4. Command History Management
history | less
history | grep /usr/bin
!88 # Run command number 88
Interactive Search (Ctrl+R):
Ctrl+R
→ Start reverse search
Ctrl+J
→ Insert and edit command
Ctrl+G
→ Cancel search
Navigation Shortcuts
Key | Action |
Ctrl+P / ↑ | Previous command |
Ctrl+N / ↓ | Next command |
Alt+< | First command in history |
Alt+> | Last command in history |
Ctrl+O | Run current command and move to next |
5. History Expansion with !
Pattern | Action |
!! | Run last command |
!number | Run specific numbered command |
!string | Run last command starting with string |
!?string | Run last command containing string |
⚠ Caution: History expansion can trigger unexpected results. Always verify before executing.
6. Recording a Terminal Session
script log.txt # Saves all terminal activity to log.txt
exit # Stop recording
Conclusion
Bash power users rely on the keyboard and its rich shortcut set to streamline their workflow. By mastering Readline edits, autocompletion, history tricks, and efficient command expansion, you can elevate your shell experience to pro level—where speed meets precision.