We can speed up our command-line experience by taking advantage of the many terminal built-in shortcuts.
- Use ctrl-l to clear the entire screen.
- Use ctrl-a to move the cursor to the beginning of the line.
- Use ctrl-e to move the cursor to the end of the line.
- Use ctrl-f to move the cursor forward one character at a time (same as the right arrow).
- Use ctrl-b to move the cursor backwards one character at a time (same as the left arrow).
- Use alt-f to move the cursor forward one word.
- Use alt-b to move the cursor backwards one word.
- Use ctrl-t to swap the current character under the cursor with the one preceding it.
- Use ctrl-k to kill the text from the current cursor location until the end of the line. ➡️
- Use ctrl-u to kill the text from the current cursor location to the beginning of the line. ⬅️
- Use alt-d to kill the text from the current cursor location through the end of the word. ➡️
- Use ctrl-w or alt-delete to kill the text from the current cursor through the beginning of the word. ⬅️
- Use the history command to view the entire history, i.e. all the commands used so far.
- History Expansion: We can easily re-run an earlier command if we have its line number from the history. Ex. to run the 73rd command in the history, we could run
!73
.