8.1 Shell Introduction
The shell is a command interpreter that provides interaction between the user and the machine, which supports specific syntax, such as logical judgments, loops, and so on.
Each user can have their own specific SHELL,CENTOS7 default shell for bash (Bourne Agin shell), as well as a shell such as Zsh,ksh.
8.2 Command History
The commands we've knocked on, Linux will be recorded, and presets can record 1000 historical commands. These commands are saved in the. bash_history file in the user's home directory. One thing you need to know is that commands that run in the current shell are saved to the. bash_history file only when the user exits the current shell normally.
Echo $HISTSIZE #查看系统设置历史命令数目, histsize is defined in Etc/profile, and is set to be re-entered into the terminal to take effect (or execution source/etc/profile will take effect)
History #查看之前的命令
History-c #清空内存中的命令历史
histtimeformat= "%y/%m/%d%h:%m:%s" #设置history查看的历史命令加上使用时的日期和时间
Permanent Save History Command Chattr +a ~/.bash_history
!! #执行上一条指令
!n #n为数字, indicating the nth instruction in the execution of the command history
!word #表示执行命令历史中最近一次以word为开头的指令
8.3 Command Completion and aliases
(1) Command completion
The TAB key is pressed once--to complete a command/path/file name.
The TAB key is pressed two times-the system will list all instructions or filenames
CentOS7 the command parameter completion is not supported by default, the installation of Bash-completion is supported (the system must be restarted before it takes effect)
(2) Aliases
Alias can be used to put a common and very long command aliases a simple and easy to remember instructions, its syntax:
Alias command aliases = ' Specific commands '
For example, alias kh= ' pwd '
Use Unalias to de-alias function
If you hit alias directly, you will see the current system preset alias.
Each user has their own configuration alias file ~/.bashrc (the. bashrc file in the home directory), where the user-defined alias is placed.
Alias aliases are defined in addition to the ~/.BASHRC in the home directory, and others are defined in the configuration file in the/etc/profile.d/directory.
8.4 Wildcard Characters
Under Bash, you can use to match 0 or more characters and match one character.
ls . txt #列出当前目录中所有以. txt End directory and file
Ls?. TXT #列出当前目录中所有以. txt a directory and file with a name that has only one character
ls [0-9a-z].txt #列出当前目录中所有以. txt that ends with a directory and file with any one or a-Z named 0-9
ls {1,2,3,a,b,c}.txt #列出当前目录中所有以. txt with the name of any directory and file named 1,2,3,a,b,c
8.5 Input and output redirection
Cat 1.txt > 2.txt #将1. txt content replaces 2.txt content
The contents of the cat 1.txt >> 2.txt #将1. txt are appended to the end of the 2.txt content
ls aaa.txt 2>err #2 > indicates error redirection, this line command indicates that the error message generated by the LS Aaa.txt will be executed to redirect the Err file
LS aaa.txt 2>>err #2 >> indicates error redirection, this line command indicates that the error message generated by the LS aaa.txt will be executed append redirect Err file
Wc-l < 1.txt #其中 < Indicates input redirection, this line command represents the number of rows that statistics 1.txt file contents
Problematic points:
(1)
&> equivalent to > + 2>
Indicates that the output content that will execute a command is correct and incorrect is redirected to somewhere
(2)
Command > 1.txt 2>&1
REDIRECT the execution command to the correct and incorrect output to 1.txt
&1 indicates that the standard output target is correct, because the >1.txt standard is correctly output to 1.txt, so &1 is 1.txt
2018-1-10 Linux Learning Notes