Bash provides several shortcuts and key combinations that can help you work more efficiently in the command line. Here are some commonly used Bash shortcuts:
- Moving the cursor:
Ctrl + A
: Move the cursor to the beginning of the line.Ctrl + E
: Move the cursor to the end of the line.Alt + F
orAlt + →
: Move the cursor forward one word.Alt + B
orAlt + ←
: Move the cursor backward one word.
- Editing the command line:
Ctrl + U
: Clear the line before the cursor.Ctrl + K
: Clear the line after the cursor.Ctrl + W
: Delete the word before the cursor.Ctrl + Y
: Paste the previously deleted text.Ctrl + L
: Clear the screen (similar to theclear
command).Ctrl + C
: Cancel the currently running command.Ctrl + D
: Exit the current shell or end input (used when there is no text on the command line).Ctrl + R
: Search command history interactively.
- Command history:
Up Arrow
orCtrl + P
: Move to the previous command in history.Down Arrow
orCtrl + N
: Move to the next command in history.Ctrl + R
: Search command history interactively.Ctrl + G
: Escape from the history search mode without executing a command.
- Tab completion:
Tab
: Auto-complete a command, file, or directory name. PressingTab
twice shows available options if there are multiple matches.
- Miscellaneous:
Ctrl + Z
: Suspend the current foreground process (can be resumed with thefg
command).Ctrl + S
: Stop the terminal output (can be resumed withCtrl + Q
).Ctrl + Q
: Resume terminal output (after it has been stopped withCtrl + S
).Ctrl + \\
: Send the QUIT signal to the current process (similar to pressingCtrl + C
, but more forceful).Ctrl + H
orBackspace
: Delete the character before the cursor.
These are just a few of the many shortcuts available in Bash. You can find more shortcuts and customize them by modifying your Bash configuration file (~/.bashrc
or ~/.bash_profile
).