First, Shell introduction
Ii. History of the Order
Historical command Store path/root/.bash_history, default can hold 1000 commands
#history//View specific history commands
[[email protected] ~]# echo $HISTSIZE//system built-in environment variable
1000
#history-c//Clears the In-memory command history, but the file holding the command is not deleted
#vi/etc/profile//Modify the History environment variable path/etc/profile, OK histsize=1000 change to 5000
[[email protected] ~]# Source/etc/profile//Modify the configuration file needs to execute this command for the configuration file to take effect
[Email protected] ~]# echo $HISTSIZE
5000
[[email protected] ~]# histtimeformat= "%y/%m/%d%h:%m:%s"//need to see the execution time of each command
[Email protected] ~]# echo $HISTTIMEFORMAT
%y/%m/%d%h:%m:%s
If you need to make the time to view each command permanent, you need to edit/etc/profile, and add a line below histsize=5000: histtimeformat= "%y/%m/%d%h:%m:%s" saves and exits for permanent use
[[email protected] ~]# chattr +a ~/.bash_history//Add hidden permission to file, this file can only append, cannot be deleted
If you do not exit the terminal normally, the command will not be saved in the. bash_history file
[[email protected] ~]#!! Two exclamation marks indicate the last command executed
[[email protected] ~]#!11//execute the 11th command in the history of the Order
[[email protected] ~]#!echo//will look backwards in the command history for the first command to start with Echo
[[email protected] ~]#!mkdir//will look backwards in the command history for the first command to start with mkdir
Iii. command Completion and aliases
In Centos7, if you need to press TEB key to complete parameters, such as systemctl restart Network This command needs to complete the restart parameter, need to install bash-completion, can be installed Yum # yum Install-y Bash-completion, restart system is required after installation
#rpm-QA Package name//See if the package is installed
[Email protected] ~]# Rpm-qa alias restartnet= ' systemctl restart Network.service '
Use restartnet to give ' systemctl restart Network.service ' This command alias, then restart the network service can execute restartnet command to Recloser NIC
[[email protected] ~]# alias//List all aliases in the system
Alias cp= ' Cp-i '
Alias egrep= ' Egrep--color=auto '
Alias fgrep= ' Fgrep--color=auto '
Alias grep= ' grep--color=auto '
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias mv= ' Mv-i '
Alias rm= ' Rm-i '
Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '
. BASHRC and/ETC/PROFILE.D have a definition of alias
#unalias restartnet//cancels custom aliases Restartnet
Iv. wildcard characters, input and output redirection
Indicates a wildcard
[[email protected] ~]# ls . txt//list. txt All files can be used with. txt
11.txt 1.txt 2.txt
[[email protected] ~]# ls txt//list. txt All files can also use txt
11.txt 1.txt 2.txt
[[email protected] ~]# ls txt //list. txt All files can also be used txt*
11.txt 1.txt 1.txt.zip 2.txt
[[email protected] ~]# ls 1 //list all files starting with 1 can use 1
11.txt 1.txt 1.txt.zip
123:
333 Yum.log
[email protected] ~]# ls?. TXT//?. TXT represents a txt file of any one character, which represents any one character
1.txt 2.txt 3.txt 4.txt a.txt
[[email protected] ~]# ls [0-3].txt//View the. txt file between the beginning 0-3 and 0-3 in square brackets to take one of the numbers
1.txt 2.txt 3.txt
[[email protected] ~]# ls [123].txt///can also take 1 2 3 in square brackets to start all. txt files
1.txt 2.txt 3.txt
[[email protected] ~]# ls [23].txt//For example, list. txt files starting with 2 3
2.txt 3.txt
[[email protected] ~]# ls [0-9a-za-z].txt//List all. txt files for 0-9 a-Z
1.txt 2.txt 3.txt 4.txt
[[email protected] ~]# ls {1,2}.txt///List of. txt files beginning with 1, 2, note that commas are required in curly brackets
1.txt 2.txt
#cat 1.txt > 2.XTX//input the output of the preceding command directly into the later file, a greater than sign will delete the original content
#cat 1.txt >> 2.XTX//Two greater than sign will not remove the original command greater than the left
#laaaa 2> 1.txt//Use 2> to enter the error information of a command into a 1.txt file
#laaaa 2>> 1.txt//use 2>> to redirect error messages to 1.txt files
is an output redirect;>> is an output append redirect;2> is an error redirect;2>> is an error append redirect
- 2> = &>
Cases:
[[email protected] ~]# ls [12].txt aaa.txt &> 3.txt//12].txt Aaa.txt the correct information and error messages are entered into the 3.txt file
[[email protected] ~]# cat 3.txt//view 3.txt file information
Ls:cannot access aaa.txt:No such file or directory
1.txt
2.txt
[[email protected] ~]# ls [12].txt aaa.txt &>> 3.txt//also supports append
[email protected] ~]# cat 3.txt
Ls:cannot access aaa.txt:No such file or directory
1.txt
2.txt
Ls:cannot access aaa.txt:No such file or directory
1.txt
2.txt
[[email protected] ~]# ls [12].txt aaa.txt > 3.txt 2>4.txt// The correct command can be entered into the 3.txt file, the error information input into the 4.txt file, later in the shell script with more, you can assign the correct and error to separate files
[email protected] ~]# cat 3.txt
1.txt
2.txt
[email protected] ~]# cat 4.txt
Ls:cannot access aaa.txt:No such file or directory
< is the input redirect, less than the left must be the command, the right is the file
[[email protected] ~]# Wc-l < 3.txt//view 3.txt file line count
2
Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection