主页 Linux Terminal Bash Shortcut Keys: Introduction and Experience
Post
Cancel

Linux Terminal Bash Shortcut Keys: Introduction and Experience

bash and its features

  • bash is essentially an executable program — a user’s working environment.
  • Under each shell you can open another shell; the newly opened shell can be called a subshell, and each shell is independent of the others.
  • You can use the pstree command to view the number of subshells under the current shell.

1. The most important: auto-completion

CommandDescription
TabAuto-completion

2. Editing and navigation

CommandDescription
Ctrl + AJump to the beginning of the current line
Ctrl + EJump to the end of the current line
Alt + FMove the cursor forward one word on the current line
Alt + BMove the cursor backward one word on the current line
Ctrl + WDelete the word before the current cursor
Ctrl + KDelete the content after the current cursor
Ctrl + UClear the entire line
Ctrl + LClear the screen, similar to the clear command
Ctrl + HBackspace, similar to the backspace key
Ctrl + TSwap the two characters before the current cursor
Esc + TSwap the two words before the current cursor

Ctrl + W and Ctrl + U are quite commonly used. Typos are a very common occurrence.

Ctrl + L goes without saying.

CommandDescription
Ctrl + CTerminate the current process
Ctrl + ZSuspend the current process in the background
Ctrl + DExit the current Shell, similar to the exit command

Ctrl + C sends the SIGINT signal to the currently running process, terminating it.

SIGINT - This signal is the same as pressing ctrl-c. On some systems, “delete” + “break” sends the same signal to the process. The process is interrupted and stopped. However, the process can ignore this signal.

Ctrl + Z doesn’t end the process; it suspends it in the background. You can later resume it with the fg command. The corresponding signal is SIGTSTP.

CommandDescription
Ctrl + RUsed to search for previously used commands

I often use history to view command history, but there’s already a ready-made shortcut for it.

After pressing Ctrl + R, type the keyword to search for; if it’s not the one you want, keep pressing Ctrl + R to iterate through the matches.

This command actually queries through the history records as well. If you don’t like this approach, you can just do history | grep xxx, which works just as well.

Reference: Linux公社

Summary

These commands noticeably improve work efficiency and need to be reviewed and memorized repeatedly. At the end of this post, I’d like to recommend Linux公社 (LinuxFans), a Linux community with a sense of history and humanism, from which I’ve learned quite a lot.

该博客文章由作者通过 CC BY 4.0 进行授权。