A novice Linux user may find the Linux terminal interface difficult to grasp, especially because it relies heavily on the arrow keys to move around. Furthermore, constantly retyping the commands, each with a slight variation, can be tedious.
Bash, on the other hand, includes a plethora of simple keyboard shortcuts and history functions that ensure efficient terminal use.
Having these terminal shortcut keyboard key combinations memorized will save you a lot of time.
To help you make better use of your time, I’ve compiled a list of the most commonly used Bash keyboard shortcuts.👇
I’d like to point out that some of these shortcuts may be dependent on the Shell you’re using. Because Bash is the most popular shell, the list is centered on it. I also tested the majority of them on ZSH and found them to be compactible.
📜 Cursor Movement
→ Ctrl + A Go to the beginning of the line you are currently typing on.
→ Ctrl + E Go to the end of the line you are currently typing on.
→ Ctrl + XX Move between the beginning of the line and the current position of the cursor.
→ Alt + F Move cursor forward one word on the current line.
→ Alt + B Move cursor backward one word on the current line.
→ Ctrl + F Move cursor forward one character on the current line.
→ Ctrl + B Move cursor backward one character on the current line.
📜 Text manipulation
→ Ctrl + U Cut the line from the current position to the beginning of the line, adding it to the clipboard. If you are at the end of the line, it cuts the entire line.
→ Ctrl + K Cut the line from the current position to the end of the line, adding it to the clipboard. If you are at the beginning of the line, cut the entire line.
→ Ctrl + W Delete the word before the cursor, adding it to the clipboard.
→ Ctrl + Y Paste the last thing from the clipboard that you cut recently (undo the last delete at the current cursor position).
📜 History access
→ Ctrl + R Lets you search through previously used commands.
→ Ctrl + G Leave history searching mode without running a command.
→ Ctrl + J Lets you copy current matched command to command line without running it, allowing you to make modifications before running the command.
→ Alt + R Revert any changes to a command you’ve pulled from your history, if you’ve edited it.
→ Ctrl + P Shows last executed command, i.e. walk back through the command history (Similar to up arrow).
→ Ctrl + N Shows next executed command, i.e. walk forward through the command history (Similar to down arrow).
📜 Terminal/Process control
→ Ctrl + L Clears the screen, similar to the clear command.
→ Ctrl + S Stop all output to the screen. This is useful when running commands with lots of long output. But this doesn’t stop the running command.
→ Ctrl + Q Resume output to the screen after stopping it with Ctrl+S.
→ Ctrl + C End currently running process and return the prompt.
→ Ctrl + D Log out of the current shell session, similar to the exit or logout command. In some commands, acts as End of File signal to indicate that a file end has been reached.
→ Ctrl + Z Suspends (pause) currently running foreground process, which return shell prompt. You can then use bg command allowing that process to run in the background. To again bring that process to foreground, use fg command. To view all background processes, use jobs command.
→ Tab Auto-complete files and directory names.
→ Tab Tab Shows all possibilities, when typed characters doesn’t uniquely match to a file or directory name.
→ Ctrl + S Gets the next most recent command
→ Ctrl + O Runs and re-enters the command found via Ctrl + S and Ctrl + R
→ Ctrl + G Exits history search mode
📜 Bash Information
→ TAB TAB List all Linux users
→ Ctrl + I Completes the command like TAB
→ Alt + ? Display files/folders in the current path for help
→ Alt + * Display files/folders in the current path as parameter
📜 Close Terminal
→ Ctrl + Shift + W To close terminal tab.
→ Ctrl + Shift + Q To close entire terminal.
That’s for today’s blog, be sure to try out these shortcuts and be amazed.
The shortcuts above are only a tip of an iceberg. The more you learn about Linux terminal commands and Bash shortcuts, the more simple and interesting Linux becomes.
If you found this blog valuable:
1. Toss me a follow for more threads on Linux and Security → @xtremepentest
2. Share so other Linux folks can find it too.