Shell Introduction
The shell is a command interpreter that provides interaction between the user and the machine
For example, we have remote login tool, it is actually a shell
The CentOS default shell is bash (Bourne Agin Shell)
·
Command history
History command
The command history exists in the user's home directory. Bash_history, such as root user is/root/.bash_history
·
History can view the command histories, the. bash_history file can be stored up to 1000, it is determined by the environment variable histsize, but history will sometimes see more than 1000 of the command histories, but that is not written into the file, still exists in memory
·
History-c can empty the current command history in memory, but does not delete the command history stored in the. bash_history file.
·
When you exit the terminal, the system will save the command history in the memory in the. bash_history file.
·
Of course we can change the. bash_history file 1000 limit, only need to edit/etc/profile, the inside histsize this line after the 1000 change, and then source/etc/profile refresh a bit, or re-enter the terminal to take effect.
·
We can also let the history command show the time, use the following command, define the Histtimeformat variable as the following format, but it only takes effect in the current terminal of the window.
histtimeformat= "%y/%m/%d%h:%m:%s"
·
If you want it to be in another window and keep it in effect, you can edit the/etc/profile file, which is placed below the Histsize line, and then source/etc/profile refreshed or re-entered the terminal to take effect.
`
If you want to permanently save your command history, do not want to be deleted, you can give it a special permission A, even if there is the maximum limit of 1000, you can save more than 1000.
·
However, if you do not exit the terminal normally, the command you have knocked on the history will be saved not all.
You want to use the last command of the command history, that is, you use the previous command can be used!!
How many lines of command history would you like to use, then you can use it! Add line number
You want to use the last command in the command history that starts with XX! Plus XX
·
Command completion and aliases
In the command to press the TAB key can be automatically complete, you can complete the file, you can also complete the command, such as you hit the file name of half and then click the TAB key System can automatically help you fill the rest of the half.
However, there is a kind of sentiment is that there are two files and above is the part of the file name you hit the beginning, this time to press the tab is no use, when we can press two, the system will show all the files you hit the beginning of the partial file name.
·
Then you can find the name of the file you want to hit and continue typing until there are no other files that start with the part of the file name you output, and then click tab to complete it.
·
In Centos7 tab can also fill in the parameters of the command, but you need to install a bash-completion package, and then restart the system to take effect.
·
Let's look at the case where bash-completion is not installed when we use systemctl restart network.service command tab
·
TAB's not responding.
We install bash-completion, then reboot and try again.
·
tab is now ready to tab out.
·
We can also set aliases for longer commands, using the alias command, as we set the Systemctl restart Network.service alias to Restartnet, and then we can use the Restartnet command instead.
·
Run alias directly to see all the aliases in the system. These aliases exist in the user's home directory under the. bashrc file (custom alias) and in the files in the/etc/profile.d/directory.
·
Alias alias using Unalias
·
Wildcard characters
Usage
Indicates that you view all files or directories in the current directory whose names end in. txt.
·
Indicates that the file or directory containing txt in the name of the current directory is viewed.
·
To view the file or directory whose name begins with 1 in the current directory
·
? usage
View the current directory The file name is a word multibyte. txt files (? denotes an arbitrary character)
·
[number-number] usage (square brackets [])
View all files ending in. txt in the current directory (also supporting letters such as A-Z or a-Z)
·
·
Check the current directory starting with 1, 2, 3, and then end with a. txt file (123 can be lost without order)
·
{character, character, character} (curly braces {})
Similar to [123], the relationship between the characters is or, (inside the curly braces, need to be separated by commas)
·
Input and output redirection
The output of the preceding command is entered into the following file, which is to overwrite the contents of the 1.txt in 2.txt. (Will delete the contents of the original 2.txt)
Cat 1.txt >2.txt
·
> Append the output of the preceding command to the following file, which is to append the contents of 1.txt to 2.txt (will not delete the contents of the original 2.txt)
Cat 1.txt >> 2.txt
·
2> the error message generated by the preceding command into a later file.
·
2>> Append the error message from the previous command to the later file.
·
&> the correct information and error messages generated by the preceding command are entered in the following file. (also support append, use &>>)
·
The correct information and error messages generated by the preceding commands are entered into the two files in the following sections to be used
·
< Enter the contents of the right file into the command on the left, as below we look at the number of lines of 1.txt content. (the left side of < must be ordered)
Shell introduces command history command completion and alias input output redirection