Shell Introduction
- The shell is a command interpreter that provides interaction between the user and the machine
- Supports specific syntax, such as logical judgment, looping
- Each user can have their own specific shell
- CentOS7 default shell is bash (Bourne Agin Shell)
- and Zsh,ksh and so on.
Command history
After the change, you must exit the terminal to re-enter or source/etc/profile change
- Variable Value re-assignment
histtimeformat= "%y/%m/%d%h:%m:%s"
[[email protected] ~]# history 1 ls 2 ls /etc/passwd 3 cat /etc/passwd 4 [[email protected] ~]# cat /etc/passwd 5 root:x:0:0:root:/root:/bin/bash 6 bin:x:1:1:bin:/bin:/sbin/nologin 7 daemon:x:2:2:daemon:/sbin:/sbin/nologin 8 adm:x:3:4:adm:/var/adm:/sbin/nologin 9 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
After the value is re-assigned
[[email protected] ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "[[email protected] ~]# history 1 2017/08/30 19:20:18 ls 2 2017/08/30 19:20:18 ls /etc/passwd 3 2017/08/30 19:20:18 cat /etc/passwd 4 2017/08/30 19:20:18 [[email protected] ~]# cat /etc/passwd 5 2017/08/30 19:20:18 root:x:0:0:root:/root:/bin/bash 6 2017/08/30 19:20:18 bin:x:1:1:bin:/bin:/sbin/nologin 7 2017/08/30 19:20:18 daemon:x:2:2:daemon:/sbin:/sbin/nologin 8 2017/08/30 19:20:18 adm:x:3:4:adm:/var/adm:/sbin/nologin
Then open a new terminal, this environment variable is not in effect.
If you want this environment variable to take effect globally, you need to edit/etc/profile to add histtimeformat= "%y/%m/%d%h:%m:%s" to the inside
fiHOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=5000HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth
Effective after Source/etc/profile
- Permanently save command history
Chattr +a ~/.bash_history
Can only append cannot delete
- If you do not exit normally, the history command is not fully saved
- !!
Represents running the last history command
- !n
Specify the number of Run history rows command
- ! command
Represents the last command in command history to enter this command
Command completion and aliases
- tab, knock, Knock, double click.
- CENTOS7 support parameter completion, the default is not, you need to install Yum install-y bash-completion after restarting the system to take effect.
- Alias aliases, give the command a new name
Alias exists in the. bashrc file in the user's home directory.
There are still some/etc/profile.d/below
Unalias to cancel a custom alias
Wildcard characters *
[[email protected] ~]# ls111 1eer 1.txt 2.txt anaconda-ks.cfg erwe[[email protected] ~]# ls *.txt1.txt 2.txt[[email protected] ~]# [[email protected] ~]# ls 1*1eer 1.txt111:[[email protected] ~]# ls *1*1eer
?
Question mark denotes any one character
[[email protected] ~]# ls ?.txt1.txt 2.txt[[email protected] ~]# ls *.txt1.txt 2.txt bbcc.txt
[]
Select Range
[[email protected] ~]# ls [123].txt1.txt 2.txt[[email protected] ~]# ls [0-9].txt1.txt
{}
It's also a choice, similar to [], but with a comma in the middle.
[[email protected] ~]# ls {1,2}.txt1.txt
Input/Output redirection >
Remove the content from the > front to redirect to the back content.
>>
Append the contents of the >> front to the following content.
2>
Indicates that the information for the run error is directed to a file
[[email protected] ~]# fddd-bash: fddd: 未找到命令[[email protected] ~]# fddd 2> 1.txt [[email protected] ~]# cat 1.txt -bash: fddd: 未找到命令
2>>
Error Append redirect
&>
Error and correct output redirection
<
Input redirect
Enter the contents of the < right side of the file into the < left command.
Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection