Introduction / Why This Matters
Knowing Bash keyboard shortcuts is like having a hotkey keyboard for a pilot. You'll be able to control the command line without taking your hands off the keyboard, cutting task completion time by 50% or more. This guide compiles the most useful and frequently used shortcuts that work by default in most Linux distributions. Once you master them, you'll no longer depend on the mouse and start working in the terminal at true speed.
Requirements / Preparation
To use these shortcuts, you'll need:
- A terminal (GNOME Terminal, Konsole, xterm, Alacritty, etc.)
- The Bash shell (usually installed by default on most distributions)
- Basic understanding of command line operation
No additional configuration or package installation is required — all shortcuts work "out of the box".
Step 1: Navigating the Input Line
These shortcuts allow you to move the cursor within the current command or text you're typing.
| Shortcut | Action | Example Usage |
|---|---|---|
Ctrl + A | Move cursor to the beginning of the line | You type git commit -m "fix bug", press Ctrl+A — the cursor moves before git. |
Ctrl + E | Move cursor to the end of the line | After Ctrl+A the cursor is at the beginning, Ctrl+E returns it to the end. |
Alt + B or Esc then B | Move cursor back one word (toward the beginning) | In the line cd /var/log/apache2, press Alt+B — the cursor jumps to /. |
Alt + F or Esc then F | Move cursor forward one word (toward the end) | The opposite of Alt+B. |
Ctrl + XX | Switch between the beginning of the line and the current cursor position | A quick way to jump back to the beginning and return without losing your place. |
💡 Tip: On many keyboards, Alt may be labeled as Meta. If Alt+B doesn't work, try Esc (release it), then B. This is equivalent to Alt+<key>.
Step 2: Editing Text
These commands help you make quick edits without using the Backspace or Delete keys.
| Shortcut | Action |
|---|---|
Ctrl + U | Delete all text from the current cursor position to the beginning of the line. |
Ctrl + K | Delete all text from the current cursor position to the end of the line. |
Ctrl + W | Delete the word before the cursor (from the start of the word to the cursor). |
Alt + D or Esc then D | Delete the word after the cursor (from the cursor to the end of the word). |
Ctrl + Y | Paste (yank) the last deleted text (like Ctrl+V in text editors). |
Ctrl + T | Swap the two characters before the cursor (e.g., if you typed sl, press Ctrl+T — it becomes ls). |
Example: You typed git comit -m "message". Place the cursor after comit, press Alt+D — it is deleted. Then start typing mit or use autocompletion.
Step 3: Working with Command History
Bash saves the history of all entered commands. These shortcuts let you quickly find and repeat them.
| Shortcut | Action |
|---|---|
Ctrl + R | Incremental search through history. Start typing part of a command (e.g., git), and Bash will show recent matches. Press Ctrl+R again for the next match. Enter to execute, Esc or arrows to edit. |
Ctrl + P or ↑ | Previous command in history (like the up arrow). |
Ctrl + N or ↓ | Next command in history (like the down arrow). |
Alt + . (period) | Insert the last argument from the previous command. Useful for cd: cd /some/long/path, then ls Alt+. → ls /some/long/path. |
Ctrl + G | Exit search mode (Ctrl+R) without executing the command. |
⚠️ Important: By default, Bash stores history in the file ~/.bash_history. The history size is controlled by the HISTSIZE variable.
Step 4: Managing Background Tasks
When you run a process (e.g., ping or top), these shortcuts let you control it without opening a new terminal.
| Shortcut | Action |
|---|---|
Ctrl + C | Interrupt the current process (send SIGINT signal). |
Ctrl + Z | Stop the process (suspend it, SIGTSTP signal) and return to the shell. The process remains in memory. |
fg | Bring a stopped process to the foreground. |
bg | Run a stopped process in the background. |
jobs | Show the list of stopped and background jobs in the current session. |
Ctrl + D | Exit the shell (equivalent to the exit command). If the input line is empty, it closes the terminal. |
Example: You ran a long command find / -name "*.log". Pressed Ctrl+Z → process stopped. Typed bg → process continues in the background, and you can keep working.
Step 5: Additional Useful Shortcuts
These combinations simplify everyday tasks.
| Shortcut | Action |
|---|---|
Tab | Autocompletion of filenames, commands, paths. Press once to complete, twice to show all options. |
Ctrl + L | Clear the terminal screen (like the clear command). |
Ctrl + I | Same as Tab (rarely used). |
Ctrl + H | Delete one character before the cursor (like Backspace). |
Ctrl + S | Stop screen output (XOFF). Useful when ls outputs too much. |
Ctrl + Q | Resume screen output (XON) after Ctrl+S. |
💡 Tip: The Ctrl+S combination can make the terminal seem "frozen". If the screen stops responding to input, try Ctrl+Q to unlock it.
Check Your Results
You've mastered these shortcuts if you can:
- Quickly navigate long commands using
Ctrl+A/E,Alt+B/F. - Delete whole words (
Ctrl+W,Alt+D) and restore them (Ctrl+Y). - Find past commands in history via
Ctrl+Rwithout full scrolling. - Stop (
Ctrl+Z) and resume (fg/bg) processes. - Use
Tabfor autocompletion andCtrl+Lto clear the screen.
Practice: Open a terminal, type a complex command (e.g., with multiple paths) and try all shortcuts from steps 1-5. Play with history: run a few commands, then press Ctrl+R and start typing their first letter.
Potential Issues
1. Shortcuts don't work in my terminal
Most often the problem is in the terminal emulator's settings. For example, in GNOME Terminal, go to Edit → Keyboard Shortcuts and ensure the shortcuts aren't remapped. Also check if "Compatibility mode" (e.g., for Ctrl+Shift+C/V) is enabled.
2. Alt+B/Alt+F do nothing
On some systems, the Alt key is used to trigger menus. Try pressing Esc, releasing it, then B or F. This is equivalent to Alt+<key>. If that still doesn't work, check the shell variable $TERM (should be xterm-256color or similar).
3. Conflict with other programs (e.g., screen/tmux)
If you use tmux or screen, they may intercept some shortcuts (especially Ctrl+B in tmux). In that case, you need to use their prefix (e.g., Ctrl+B then [ for copy mode in tmux). Outside multiplexers, regular Bash shouldn't have issues.
4. History isn't saved between sessions
By default, Bash saves history only on clean exit (exit or Ctrl+D). If you close the terminal with the "X" button, history may be lost. To avoid this, add to ~/.bashrc:
# Save history after each command, not just on exit
shopt -s histappend
PROMPT_COMMAND='history -a'
After this, every command will be immediately written to ~/.bash_history.