Bash Keyboard Shortcuts
Speed up your command line workflow
⌨️ What are Bash Shortcuts?
Bash keyboard shortcuts are key combinations that help you navigate, edit, and control the command line efficiently. Learning these shortcuts dramatically improves your productivity and makes terminal work faster and more enjoyable.
# Example: Clear screen
Ctrl + L
# Example: Cancel current command
Ctrl + C
Result:
Screen cleared instantly Command execution stopped
Essential Shortcuts
Navigation
Move cursor quickly
Ctrl + A # Start
Ctrl + E # End
Editing
Cut, copy, and paste text
Ctrl + K # Cut
Ctrl + Y # Paste
History
Access previous commands
Ctrl + R # Search
↑ ↓ # Browse
Control
Manage command execution
Ctrl + C # Cancel
Ctrl + Z # Suspend
🔹 Cursor Movement
Mastering cursor movement shortcuts eliminates reliance on arrow keys, dramatically speeding up command-line editing. Press Ctrl+A to jump to the line start and Ctrl+E for the end. Move forward/backward one word with Alt+F and Alt+B. Use Ctrl+XX to toggle between the start and current position. These keystrokes allow rapid navigation within long or complex commands, making correction and refinement efficient. Integrating these into your workflow is a fundamental skill for proficient terminal usage.
# Move to beginning of line
Ctrl + A
# Move to end of line
Ctrl + E
# Move forward one word
Alt + F (or Esc + F)
# Move backward one word
Alt + B (or Esc + B)
# Move forward one character
Ctrl + F
# Move backward one character
Ctrl + B
Example:
Before: echo hello |world Ctrl + A: |echo hello world Ctrl + E: echo hello world| Alt + B: echo hello |world
🔹 Text Editing
Powerful in-line text editing shortcuts let you modify commands instantly without reaching for the mouse. Delete from cursor to line end with Ctrl+K, or to start with Ctrl+U. Remove the previous word using Ctrl+W. Paste the last deleted text (Ctrl+Y). Transpose characters (Ctrl+T) or undo (Ctrl+_). These operations streamline command construction, fix typos quickly, and reuse text fragments, greatly enhancing editing efficiency and reducing frustration during complex command entry.
# Delete character under cursor
Ctrl + D
# Delete character before cursor (backspace)
Ctrl + H
# Cut from cursor to end of line
Ctrl + K
# Cut from cursor to beginning of line
Ctrl + U
# Cut word before cursor
Ctrl + W
# Paste last cut text
Ctrl + Y
# Undo last action
Ctrl + _
# Transpose characters
Ctrl + T
Example:
Command: echo hello world Ctrl + W: echo hello | Ctrl + Y: echo hello world| Ctrl + K: echo hello |
🔹 Command History
Efficiently accessing and searching command history saves time and prevents retyping errors. Browse sequentially with up/down arrows. Search interactively in reverse with Ctrl+R. Use !! to rerun the last command or !string to run the last command starting with 'string'. Access arguments from the previous command with Alt+.. This deep integration with your command past accelerates workflow, facilitates complex command reuse, and serves as a practical memory aid for your terminal activities.
# Previous command
↑ (Up Arrow)
# Next command
↓ (Down Arrow)
# Search command history
Ctrl + R
# Continue searching backward
Ctrl + R (press again)
# Continue searching forward
Ctrl + S
# Execute found command
Enter
# Edit found command
Esc
# Recall last argument of previous command
Alt + . (or Esc + .)
Example:
Ctrl + R: (reverse-i-search)`git': git status Press Ctrl + R again: git commit -m "message" Press Enter: executes the command
🔹 Process Control
Process control shortcuts manage command execution, essential for multitasking and handling long-running jobs. Suspend the foreground process with Ctrl+Z, then resume it in the background with bg or foreground with fg. Terminate the current command with Ctrl+C. Send an EOF (End-Of-File) with Ctrl+D to exit shells or interactive programs. These controls give you immediate command over execution flow, allowing you to pause, switch, or cancel tasks without losing your shell session.
# Cancel current command
Ctrl + C
# Suspend current process (send to background)
Ctrl + Z
# End of file (exit shell or end input)
Ctrl + D
# Pause terminal output
Ctrl + S
# Resume terminal output
Ctrl + Q
# Send EOF signal
Ctrl + D
Example:
$ ping google.com Ctrl + C: ^C (command cancelled) $ sleep 100 Ctrl + Z: [1]+ Stopped $ fg: (brings back to foreground)
🔹 Screen Control
Screen control shortcuts manage terminal display issues and improve readability. Clear the entire screen with Ctrl+L for a fresh workspace. Redraw the current line with Ctrl+R if display corruption occurs. Use the reset command (or Ctrl+J followed by 'reset') to fully restore the terminal after binary output garbles it. These tools help maintain a clean, functional workspace, which is especially important when working with commands that produce complex or raw output.
# Clear screen
Ctrl + L
# Clear screen (alternative)
clear
# Redraw current line
Ctrl + L (in some terminals)
# Reset terminal
reset
# Exit shell
Ctrl + D (at empty prompt)
# Logout
exit
Result:
Ctrl + L: Screen cleared, prompt at top clear: Same as Ctrl + L reset: Terminal completely reset
🔹 Tab Completion
Tab completion accelerates command entry and reduces errors by auto-filling commands, filenames, and paths. Press Tab once to complete the current word; press it twice to list all possible completions. It works for commands in your PATH, files/directories in the current directory, and even variable names. This feature not only speeds up typing but also acts as a discovery tool and a guard against typos in critical commands or file paths, making shell interaction faster and more accurate.
# Complete command or filename
Tab
# Show all possible completions
Tab Tab
# Complete variable name
$VAR[Tab]
# Complete username
~user[Tab]
# Complete hostname
ssh user@host[Tab]
Example:
$ cd Doc[Tab] $ cd Documents/ $ git che[Tab][Tab] checkout cherry-pick cherry
🔹 Advanced Shortcuts
Advanced editing shortcuts unlock powerful transformations for expert-level command-line efficiency. Change the case of the current word with Alt+U (uppercase) or Alt+L (lowercase). Swap the current word with the previous using Alt+T. Execute a specific history command by number with !n. Expand history references like !!:s/old/new/ for substitution. Mastering these techniques enables lightning-fast editing and complex command manipulation directly at the prompt.
# Capitalize word
Alt + C
# Uppercase word
Alt + U
# Lowercase word
Alt + L
# Transpose words
Alt + T
# Execute command from history
!number
# Repeat last command
!!
# Last argument of previous command
!$
# All arguments of previous command
!*
Example:
$ echo hello world $ !! echo hello world $ mkdir /tmp/test $ cd !$ cd /tmp/test