Linux Keyboard Shortcut Commands
Linux offers many keyboard shortcuts to streamline command-line navigation, editing, and efficiency. Here’s a breakdown of some of the most useful shortcut commands, organized by function:
1. Navigating the Command Line
Ctrl + A
: Move to the beginning of the line.Ctrl + E
: Move to the end of the line.Alt + F
: Move forward by one word.Alt + B
: Move backward by one word.Ctrl + Left Arrow
: Move backward by one word.Ctrl + Right Arrow
: Move forward by one word.
2. Editing Commands
Ctrl + U
: Clear everything from the cursor to the beginning of the line.Ctrl + K
: Clear everything from the cursor to the end of the line.Ctrl + W
: Delete the word before the cursor.Alt + D
: Delete the word after the cursor.Ctrl + L
: Clear the terminal screen (similar toclear
command).Ctrl + Y
: Paste (yank) text that was cut withCtrl + U
orCtrl + K
.Alt + .
: Insert the last argument from the previous command.
3. Command History
Up Arrow
: Show the previous command in history.Down Arrow
: Show the next command in history.Ctrl + R
: Reverse search through command history. Start typing to find a previous command that matches.Ctrl + G
: Exit reverse search mode.!!
: Execute the last command again.!<command>
: Execute the most recent command that starts with<command>
. For example,!ls
runs the lastls
command.
4. Working with Processes
Ctrl + C
: Terminate the current process.Ctrl + Z
: Suspend the current process and move it to the background.fg
: Bring the most recent suspended process to the foreground.bg
: Resume a suspended process in the background.
5. Tab Completion and Auto-Suggestions
Tab
: Auto-complete files, directories, and command names.Double Tab
: Show possible completions if there are multiple matches for auto-completion.
6. Managing Terminal Sessions
Ctrl + D
: Logout of the current terminal session or close the terminal if in a graphical interface.Ctrl + Shift + T
: Open a new tab in the terminal (in most terminal emulators).Ctrl + Shift + N
: Open a new terminal window.
7. Screen and Scroll Management
Shift + Page Up
: Scroll up in the terminal output.Shift + Page Down
: Scroll down in the terminal output.Ctrl + S
: Pause output to the screen (useful for reading logs).Ctrl + Q
: Resume output to the screen after pausing it withCtrl + S
.
8. Bash Shortcuts for Substitution and Expansion
!$
: Represents the last argument from the previous command.!*
: Expands to all arguments from the previous command.!^
: Expands to the first argument from the previous command.^old^new
: Replaces the first instance of "old" with "new" in the previous command and executes it.
9. Customizing the Command Prompt
PS1
Variable: Customize the prompt. For example,PS1="\u@\h:\w\$ "
sets the prompt to display the user (\u
), host (\h
), and working directory (\w
).
Example command to change prompt temporarily:
These shortcuts greatly improve efficiency and help streamline workflows in the Linux command line, especially as you get accustomed to using them regularly.