How to improve the efficiency of command line in Linux
Source: Internet
Author: User
How to improve the efficiency of Linux Command Line-Linux general technology-Linux technology and application information, the following is a detailed description. I. Customize the/etc/inputrc File
By setting the INPUTRC environment variable (see the/etc/profile file), it mainly defines or changes the definition of some function keys to better use the command line, generally, the INPUTRC environment variable points to the/etc/inputrc file. You only need to edit the/etc/inputrc file and use the Tab key command to complete the full function, and then you can implement the DOSKEY function similar to MSDOS.
The following uses Redhat 7.3 as an example to describe that the bash shell version is 2.0.5. You can customize and modify the file as needed. For more information, see man bash.
Example: The content of the/etc/inputrc file is as follows:
Set bell-style none
Set meta-flag on
Set input-meta on
Set convert-meta off
Set output-meta on
Set show-all-if-ambiguous On
"E [1 ~ ": Beginning-of-line # home
"E [2 ~ ": Insert-last-argument # insert
"E [3 ~ ": Delete-char # delete
"E [4 ~ ": End-of-line # end
"E [5 ~ ": Backward-kill-word # page up
"E [6 ~ ": Kill-word # page down
# (F1... F5) are "e [[A"... "e [[E"
"E [18 ~ ": History-search-forward # F7
"E [19 ~ ": History-search-backward # F8
The specific modification instructions are as follows (note the content in [] below is the key pressed ):
Set bell-style none
Turn off the sound from a computer speaker.
Set meta-flag on
Set input-meta on
Set convert-meta off
Set output-meta on
These lines mainly implement the input and display of Chinese characters on the command line. For example, you want to enter the name of a Chinese character file.
Set show-all-if-ambiguous On
This line mainly makes the command completion function better available. Many Linux beginners do not know this function, that is, using the [Tab] key can reduce keyboard hitting and spelling errors. For example, if you want to run ifconfig name, you enter if and press the [Tab] key twice, then all commands starting with if will appear, you can also enter the file name and directory name using this method. After the preceding command is opened, you can use the [Tab] key and press it only once, which is more convenient and convenient.
"E [1 ~ ": Beginning-of-line # home
"E [2 ~ ": Insert-last-argument # insert
"E [3 ~ ": Delete-char # delete
"E [4 ~ ": End-of-line # end
"E [5 ~ ": Backward-kill-word # page up
"E [6 ~ ": Kill-word # page down
These lines are used to make it easy to edit the command line. The [home], [delete], and [end] keys retain the original intent, it refers to moving to the beginning of the command line, deleting a character, and moving to the end of the command line. The [insert] key is defined as the last parameter for inserting the previous command. For example, run the following command:
$ Mount/mnt/cdrom
$ Cd [space] [insert]
# It is equivalent to executing cd/mnt/cdrom
How many times can I press the [insert] key to see what will happen?
The [Pageup] and [PageDown] keys are defined to delete words both forward and backward.
"E [18 ~ ": History-search-forward # F7
"E [19 ~ ": History-search-backward # F8
[F7] and [F8] are defined as the command history search function, which is similar to the DOSKEY function of MSDOS. For example, the mount command has been used before, if you input mount again and press [F8], the previously used commands will be called out, especially when the command has many very long parameters.
Ii. Install bash-completion
If you frequently use the [tab] key to complete the function, you will find its shortcomings, you can find that it cannot complete the required parameters, files, or directories based on specific needs or commands. For example, if you run cd [tab], the system will display the file with the directory. In fact, you only need to set the file type to directory. Bash has been added to the command complete internal commands since version 2.05, so that it can use complex command line interfaces to implement programmable completion programs through a complex script bash_completion, reduce the routine maintenance work of the system administrator, reduce errors, and improve work efficiency.
The procedure is as follows:
1. download the latest bash-completiton script and check the bash version number [execute bash -- version]. if the version is earlier than 2.0.5, it is best to upgrade bash.
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.