Linux custom shortcuts

Source: Internet
Author: User
One feature of Linux is its many commands and powerful functions. frequent command input is not only troublesome but also heavy-workload. although it can be supplemented by the TAB & gt; command, 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 put...

 

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字符> ":" <执行的命令> "

 

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 | restart | close | the specified service process

3. view the status of the specified service

4. open the specified configuration file of the specified service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.