Introduction / Why This Is Needed
Working in the Linux command line is a powerful tool for administration, development, and automation. However, constantly entering commands with the mouse or moving around with arrow keys can slow down your workflow. Keyboard shortcuts (hotkeys) allow for fast navigation, command editing, and process management, saving precious seconds. After mastering these combinations, you'll notice a significant productivity boost, especially during long terminal sessions. In this guide, we'll cover the most useful shortcuts for bash and zsh—the most popular Linux shells.
Requirements / Preparation
Before you begin, make sure you have:
- Access to a Linux terminal — any graphical terminal (gnome-terminal, konsole, xterm) or virtual console (Ctrl+Alt+F1-F6).
- An installed shell — bash (default in most distributions) or zsh. You can check your current shell with:
echo $SHELL - Basic command-line knowledge — the ability to enter and run simple commands.
💡 Tip: If you're a beginner, start with bash, as its keyboard shortcuts are the most universal. Zsh offers additional features, but the basic combinations are compatible.
Essential Keyboard Shortcuts for Navigation
These combinations will help you move quickly within the input line without using the mouse or arrow keys.
Character and Word Navigation
Ctrl+A— Move to the beginning of the command line.Ctrl+E— Move to the end of the command line.Ctrl+B— Move backward one character (like the ← arrow).Ctrl+F— Move forward one character (like the → arrow).Alt+B— Move backward one word (delimiters: space, hyphen, slash).Alt+F— Move forward one word.
⚠️ Important: On some systems, the
Altkey may not work in the terminal by default. In this case, useEscbefore pressingBorF(e.g., pressEscthenBto move back a word).
Quick Position Switching
Ctrl+XX— Toggle between the beginning of the line and the current cursor position (works in bash and zsh when theset -o emacsoption is enabled).
Example: You typed a long command but need to fix the beginning. Press Ctrl+A, make edits, then Ctrl+XX — the cursor will return to where you originally stopped.
Shortcuts for Command Editing
These combinations speed up typo correction and command modification.
Text Deletion
Ctrl+U— Delete everything from the cursor to the beginning of the line.Ctrl+K— Delete everything from the cursor to the end of the line.Ctrl+W— Delete the word before the cursor (from the current position to the previous delimiter).Alt+D— Delete the word after the cursor (from the current position to the next delimiter).Ctrl+D— Delete the character under the cursor (like theDeletekey).
Pasting and Undoing
Ctrl+Y— Paste (yank) the last deleted text (combinations likeCtrl+U,Ctrl+K,Ctrl+Wsave text to a buffer).Alt+.(period) — Insert the last argument from the previous command. PressingAlt+.repeatedly cycles through arguments from history.Ctrl+_(orCtrl+Shift+-) — Undo the last change (likeundo).
Example: You entered cp file1.txt /path/to/destination/. Then you want to copy file2.txt to the same location. Type cp file2.txt and press Alt+. — it will insert /path/to/destination/.
Correcting Typos
Alt+T— Swap the two most recent words (useful if you reversed the order).Ctrl+T— Swap the two most recent characters (for correcting transposed letters).
Searching and Working with Command History
The terminal saves the history of all entered commands. These shortcuts let you quickly find and repeat them.
Reverse Search
Ctrl+R— Start a reverse search through history. Begin typing part of a command, and the terminal will show the first match. PressCtrl+Ragain to find earlier matches.Ctrl+Gexits the search while keeping the found command in the line.Ctrl+S— Forward search (may be blocked in some terminals; unlock withstty -ixon).
History Navigation
Ctrl+P(or ↑ arrow) — Previous command in history.Ctrl+N(or ↓ arrow) — Next command in history.Ctrl+G— Exit search mode or cancel current input.!!— Execute the last command (handy if you forgotsudo). Example:sudo !!.!$— Use the last argument of the last command. Example:mv file1.txt /tmp/thencat !$will open/tmp/.!^— Use the first argument of the last command.!-2— Execute the command entered two steps back in history.
Process Management
When a process is running in the terminal, these shortcuts help you manage it without closing the session.
Ctrl+C— Interrupt the current process (sends SIGINT). Use if a command is stuck or you need to stop it.Ctrl+Z— Suspend the process (sends SIGSTOP) and return to the shell. The process remains in memory.Ctrl+D— Send EOF (end-of-file). If typed on an empty line, it terminates the current shell session (likeexit).bg— Resume a suspended process in the background.fg— Resume a suspended process in the foreground (in the current terminal).jobs— List all suspended and background jobs in the current session.
Example: You started sleep 1000 but need to return to the terminal. Press Ctrl+Z, then bg — the process will continue running in the background.
Advanced Configuration and Customization
While the standard shortcuts are sufficient for most tasks, you can customize your own or improve existing ones.
Configuring bash via ~/.inputrc
The ~/.inputrc file controls readline behavior (the library used by bash). Add lines for new shortcuts.
Example: Make Ctrl+Left/Right work for word navigation (by default, they send escape sequences in some terminals).
# ~/.inputrc
"\e[1;5D": backward-word # Ctrl+Left
"\e[1;5C": forward-word # Ctrl+Right
"\e[5~": beginning-of-history # PageUp for history search
"\e[6~": end-of-history # PageDown
After saving the file, restart the terminal or run bind -f ~/.inputrc.
Configuring zsh via ~/.zshrc
In zsh, shortcuts are managed via bindkey. Add to ~/.zshrc:
# Example: Ctrl+Left/Right for word navigation
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
# Enable emacs mode (zsh may default to vicmd-mode)
bindkey -e
Reload zsh: source ~/.zshrc.
Creating Macros
You can assign a key to a sequence of commands. For example, in bash via ~/.inputrc:
# Ctrl+T inserts the date in YYYY-MM-DD format
"\C-t": "date +%Y-%m-%d"
In zsh via ~/.zshrc:
bindkey "^T" insert-datetime
insert-datetime() {
LBUFFER+=$(date +%Y-%m-%d)
}
zle -N insert-datetime
Practical Tips for Memorization
- Start small — Learn 5-7 of the most common shortcuts (e.g.,
Ctrl+A,Ctrl+E,Ctrl+U,Ctrl+K,Ctrl+R). Use them consciously every day. - Create a cheat sheet — Print a table of shortcuts and place it near your monitor. We've prepared a PDF cheat sheet for you — download it here (link will be added in the real article).
- Practice outside work hours — Open a terminal and try typing long commands using only shortcuts, without the mouse.
- Use
Ctrl+P/Ctrl+Ninstead of arrows — This habit forms quickly. - Don't fear mistakes — If you accidentally delete text,
Ctrl+Ywill restore it.
Checking Your Results
After studying this guide, you should be able to:
- Move quickly along long commands using
Ctrl+A/E/B/F. - Correct typos without retyping (e.g.,
Ctrl+Uto delete part of a command). - Find and repeat previous commands via
Ctrl+Rand!!. - Manage background tasks (
Ctrl+Z,bg,fg). - Customize your own shortcuts via config files if needed.
Test yourself: Open a terminal and enter a complex command, for example:
sudo apt update && sudo apt upgrade -y
Now, without using arrows or the mouse:
- Move to the start of the line (
Ctrl+A), delete part (Ctrl+K), paste it back (Ctrl+Y). - Find the command
sudo apt updateviaCtrl+R. - Interrupt execution (if it's running) via
Ctrl+C.
If everything works — you're on the right track!
Potential Issues
Shortcuts Don't Work in My Terminal
- Problem:
Alt+BorAlt+Fdo nothing.- Solution: Use
Escinstead ofAlt, then pressBorF. Or configure your terminal to sendMetasequences (e.g., in gnome-terminal: Settings → Keys → "Alt sends ESC").
- Solution: Use
- Problem:
Ctrl+Left/Rightdon't move by words.- Solution: Configure
~/.inputrcor~/.zshrcas shown above. Ensure the escape sequences match your terminal (check by runningcatand pressing the combination).
- Solution: Configure
Conflicts with Applications
- Problem: In
vimornano, keyboard shortcuts may differ or be intercepted.- Solution: In
vim, useCtrl+[instead ofEsc, and for word navigation useW/Bin normal mode. Innano, shortcuts are similar to GUI editors (e.g.,Ctrl+←). Consider the application context.
- Solution: In
Zsh in Vi Mode
- Problem: By default, zsh may use
vimode (like vim), where shortcuts are different.- Solution: Switch to
emacsmode (more familiar for bash users) by addingbindkey -eto~/.zshrc.
- Solution: Switch to
Resetting Settings
- If you break your configuration, delete or rename
~/.inputrc/~/.zshrcand restart the terminal — default settings will be restored.
Different Terminals
- In graphical terminals (gnome-terminal, konsole), shortcuts usually work out of the box. In the console (Ctrl+Alt+F1), some escape sequences may differ. Test in your environment.