Transferred from: http://www.opsers.org/linux-home/base/full-version-of-bash-keyboard-shortcuts.html#toc-3
Living in the Bash shell, memorizing the following shortcuts will greatly improve the efficiency of your command line operations.
Edit command
- Ctrl + A: Move to the beginning of the command
- Ctrl + E: Move to the end of the command line
- Ctrl + F: Move forward by character (right)
- Ctrl + B: Move back by character (left)
- Alt + F: Move forward by word (right)
- Alt + B: Move back by word (left)
- Ctrl + XX: Moves between the beginning of the command line and the cursor
- Ctrl + u: Delete from cursor to beginning of command
- Ctrl + K: delete from cursor to end of command line
- Ctrl + W: Delete from the cursor to the top of the word
- Alt + D: Delete from the cursor to the end of the word
- Ctrl + D: Remove the character at the cursor
- Ctrl + H: Delete the characters before the cursor
- Ctrl + y: After pasting to the cursor
- Alt + C: Change the word from the cursor to the uppercase letter
- Alt + u: Change from the cursor to all uppercase words
- Alt + L: Change from cursor to all lowercase words
- Ctrl + t: Swap cursor and previous characters
- Alt + t: Swap cursor and previous words
- Alt + Backspace: Similar to Ctrl + W, there are some differences in separators [Thank you Rezilla]
Re-execute command
- Ctrl + r: Reverse Search Command History
- Ctrl + G: Exit from History search mode
- Ctrl + P: previous command in history
- Ctrl + N: The next command in history
- Alt +.: Use last parameter of previous command
Control commands
- Ctrl + L: Clear screen
- Ctrl + O: Executes the current command and selects the previous command
- Ctrl + S: Block screen output
- Ctrl + Q: Allow screen output
- Ctrl + C: Terminate command
- Ctrl + z: Suspend command
Bang (!) command
- !! : Executes the previous command
- !blah: Executes the most recent command starting with Blah, such as!ls
- !blah:p: Print output only, without performing
- !$: The last parameter of the previous command, with Alt +. Same
- !$:p: Print out the contents of the!$
- !*: All parameters of the previous command
- !*:p: Print out the contents of the!*
- ^blah: Delete blah from previous command
- ^blah^foo: Replace blah in the previous command with Foo
- ^blah^foo^: Replace all blah in the previous command with Foo
Friendly tips :
- Most of the Bash shortcuts described above only work when in Emacs edit mode, and if you configure Bash as VI edit mode, it will follow the VI key bindings. Bash defaults to emacs edit mode. If your Bash is not in Emacs edit mode, you can
set -o emacs
set it up.
- ^s, ^q, ^c, ^z are processed by the terminal equipment, can be set by the
stty
command.
Go Bash Shortcut Full version