24+ Linux terminal shortcuts every power Linux user should know π§΅β
The Linux terminal interface may be difficult for a new Linux user to grasp, especially because it relies heavily on the arrow keys to move around. Furthermore, it can be tiresome to constantly retype the commands, each with a slight variation.
Bash, on the other hand, comes with a plethora of simple keyboard shortcuts and history functions to 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 frequently used Bash keyboard shortcuts βπ§
π‘ I should mention that some of these shortcuts may be dependent on the Shell you're using. Because Bash is the most popular shell, this list is centered on it. I also ran the majority of them through ZSH and discovered that they were compatible.
π§ 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).
π§ Access your History
β 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).
β Ctrl + _ - Undo previous command β Ctrl + O - Executes and re-enters the command found via Ctrl + R and Ctrl + S
β !! - Execute last command
β !* - Execute previous command except its first word.
β !*:p - displays arguments of the last command.
β !n - Executes the nth command in history
β !n:p - Displays the nth command and adds it as the recent command in history.
β !$ - displays the forth last argument of the previous command.
β !^ Substitutes first argument of last command in the current command.
β ^foo^bar - Replaces foo with bar.
β !n - Executes nth command from the bash history.
π§ 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 cmd.
β 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.
π§ 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 concludes today's thread; be sure to experiment with these shortcuts and be amazed. The shortcuts listed above are only the tip of the iceberg.
The more you learn about Linux terminal commands and Bash shortcuts, the more straightforward and appealing Linux becomes.
If you found this thread valuable:
1. Toss us a follow for more daily threads on Linux, sysadmin and devops β @linuxopsys
2. Like and RT the first tweet so other Linux folks can find it too.