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 + ForAlt + →: Move the cursor forward one word.Alt + BorAlt + ←: 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 theclearcommand).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 ArroworCtrl + P: Move to the previous command in history.Down ArroworCtrl + 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. PressingTabtwice shows available options if there are multiple matches.
- Miscellaneous:
Ctrl + Z: Suspend the current foreground process (can be resumed with thefgcommand).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 + HorBackspace: 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).