Set the hotkey at the command prompt in Linux
One feature of Linux is its many commands and powerful functions. Frequent command input is not only troublesome, but also requires a large amount of work. Although it can be done by using tab> command supplement, or you can use aliase to simplify the input of a command, but this does not fundamentally solve the problem of too many times of hitting the keyboard.
You can assign a combination of any command or command to a key on the keyboard, which can be Alt + [A-Z],
CTRL-[A-Z], ALT + Shift + [A-Z], F1-F12, Ctrl-f [1-12], alt-f [1-12], alt + Shift + F [1-12], even more incredible is that you can even add a "parameter" to the function key so that when you press that key, it will wait for you to enter the corresponding parameters and run different commands according to different parameters.
Of course, there are some hotkeys that will be captured by the terminal, such as the common Ctrl-D/C/Q/Z, but it doesn't matter, there are still many hot keys available!
The configuration file defining the hotkey is/etc/inputrc or ~ /. Inputrc. The format of the hotkey is defined as follows:
"<ASCII character corresponding to the hotkey>": "<executed command>"
The ASCII characters corresponding to the hotkey can be entered by pressing Ctrl-V first and then the hotkey. For example, the character corresponding to Ctrl-G is ^ G, the characters corresponding to alt-P are ^ [p, Ctrl-alt-H and ^ [^ h.
You can use/C to replace Ctrl,/m to replace ALT,/m-/C to replace alt-Ctrl, such as/C-M = Ctrl-m, /m-/C-H = alt-Ctrl-M. you can also use/E to represent tables ^ [.
Let's take a look at some basic hotkey definitions (the letters in the hotkey are case-insensitive ):
"^ [-": "Su-/C-M" # press Alt +-Execute Su-command, end/C-M indicates entering the defined command and press enter, it can also be expressed with A/N in a more concise manner.
"/M-/C-G": "Gaim &>/dev/null & disown/C-M"
# Press Ctrl-alt-g to open Gaim in the current shell and run it independently. That is, GAIM will not be closed even if you quit the shell.
Other key combinations can be configured as needed.
You may think that defining hot keys is too messy and hard to remember. There are some restrictions. This problem will be solved later.
Generally, we can use the up and down arrow keys to search for the command history list and enter the command again. However, the arrow keys are too far away from the primary key area. If you use them frequently, it will delay a lot of time, in addition, it is not convenient to move the right hand. Is there any way to move the function of the direction key to the place where we often> knock commands? For example, if you use Alt + J = down arrow for downward search, ALT + k = up arrow for downward search
You can do this by defining the hotkey:
"/Eh": "^ [OD" # Move left
# Alt-H shifts one character to the left, which is equivalent to left arrowgh. Here ^ [OD is the ASCII character of the up arrow key. The input method is similar to the one mentioned above.
"/El": "^ [OC" # Move right
# Alt-l shifts one character to the right, which is equivalent to right arrow
"/EJ": "^ [ob" # Move Up
# Alt-J move down, equivalent to up arrow
"/EK": "^ [OA" # Move down
# Alt-K move up, equivalent to Down Arrow
"/EI": "^? "# Left earse one character
# Alt-I: delete a character from the left, which is equivalent to backspace.
"/Eo": delete-Char # Right earse one character
# Alt-O delete a character from the right, which is equivalent to delete
"/EN": backward-kill-word # Left kill one word
# Alt-N delete a word from the left
"/Em": Kill-word # right kill one word
# Alt-M delete a word to the right
"/Ea": "^ [n ^ [n ^ [n ^ [n ^ [n ^ [n ^ [N" # kill to the head
# Alt-A Delete the current position to the beginning, that is, multiple Alt-N times (A --> ahead)
"/EE": "^ [m ^ [m ^ [m ^ [m ^ [m ^ [m ^ [m ^ [M" # kill to the head
# Alt-e Delete the current position to the end, that is, multiple alt-m times (E --> end)
"/EP": insert-last-argumem"
# Alt-P Insert the last parameter of the previous command (p --> paste)
"/Ew": Forward-word
# By default, alt-F (forward) jumps to the end of the current word. If it is already at the end of the word, it jumps to the end of the next word (one word on the right ).
"/EQ": backward-word
# By default, alt-B (backward) jumps to the beginning of the current word. If it is already in the beginning of the word, it jumps to the beginning of the previous word (one word on the left ).
I found that the F and B keys are too far away from each other, which is inconvenient. I changed them to alt-Q and Alt-W respectively, but alt-F/B can still be used.
In this way, when you enter commands, you almost do not have to leave the primary key area, move the cursor, delete characters, delete words, and search for historical commands from top to bottom. This is much easier than before. However, it may be a bit difficult at first, just like using vi, but you will be proficient after several times.
In Linux, the configuration of most services is based on the configuration file. Generally, the configuration file of a service must be changed to take effect immediately, you also need to restart the direct or attached daemon of the service. Don't you think that "service XXX restart/reload or killall-hup XXX after VI/etc/xxx. conf is complete" is complicated? What if there are many services to be configured and debugging is not stopping? In addition, when we use Linux, it is inevitable that a service process will be terminated or started from time to time, and a large number of commands will be entered. It seems unlikely that a hotkey is specified for each service. What if we assign a hot key as a basic key and the corresponding service is "parameter?
For example, assign alt-s (s --> Start) as the basic key for starting the service. The first two characters of the service name are "Parameters" for starting the service ", then you can start a service at will as follows:
"/Essm": "service SMB start/N"
#/ES = alt-S, Sm = SMB,
# That is, you can start the samba service process by pressing alt-s and then entering Sm (the input SM is not displayed on the terminal, don't worry about the time delay between pressing the key and entering the "parameter". You can press Alt-S, compress it out, and enter SM.
"/Esht": "service httpd start/N" # ht = httpd, start the apache service
Similarly, we grant
Alt-D (d --> shutdown) is the basic key for stopping services.
Alt-R (r --> restart) is the basic key for restarting the service.
Alt-T (t --> Status) is the basic key for viewing the service status
Alt-C (c --> Configure) is the basic key for opening the master configuration file corresponding to the service
For example, "/ecnf": "VI/etc/exports/N" # alt-C + NF open the NFS configuration file
"/Ecsm": "VI/etc/samba/smb. conf/N" # alt-C + SM open the SMB configuration file
If a service (such as SSH) has two configuration files, you can add a number after it, such:
"/Ecssh1": "VI/etc/ssh/sshd_config/N" # Open the sshd server configuration file
"/Ecssh2": "VI/etc/ssh/ssh_config/N" # Open the sshd client configuration file
What if you want to execute an application? You can use alt-X as the basic key (X --> execcute), for example:
"/Exga": "Gaim &>/dev/null & disown & clean/N"
"/Exxm": "xmms &>/dev/null & disown & clean/N"
"/Exvm": "VMware &>/dev/null & disown & clean/N" "/exna ": "Nautilus &>/dev/null & disown & clean/N"
And so on ....
Up to now, we only need to press 1 key combination + 2 characters to implement the following functions:
1. Run the specified application
2. Start and restart to close the specified service process
3. view the status of the specified service
4. Open the specified configuration file of the specified service
Author: http://www.tanvy.com/linux/showarticle.asp? Id = 161 & sort = Linux % BC % Ca % F5