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
- and zsh, Ksh and so on.
Command history
The history command is saved in the user's home directory. Bash_history
[[email protected] ~]# cat-n/root/.bash_history 1 init 0 2 dhclient ... 987 PS aux| grep httpd 988 cat/etc/selinux/config 989 init 0[[email protected] ~]# echo $HISTSIZE #命令最大保存数量1000 # You can change the maximum number of saves through the environment variable $HISTSIZE, modify it in configuration file/etc/profile, and the source /etc/profile takes effect #history-c Can empty the memory of the command history empty # cannot empty records in the command history file [[email protected] ~]# history-c #刚输入的命令不会马上记录到命令历史文件中, only after exiting the terminal will enter # Modify the History command format to display the time. Added in the configuration file. #HISTTIMEFORMAT = "%y/%m/%d%h:%m:%s" 1. Quick Display the previous command!! 2. Run a command in the History list!n3. Reverse the first command starting with XXX! XXX4. Save the command file permanently, only add cannot delete chattr +a ~/.bash_history
Command completion and aliases
TAB key, complete command and file path.
Auto-complete command parameter completion, need to install Yum install-y bash-completion, and then restart the system.
[Email protected] ~]# systemctl rereboot reload-or-restart reset-failedreenable Reload-or-try-restart restartreload Rescue
The custom alias is placed in the user's home directory of the ~/.BASHRC, there are some/etc/profile.d/in the script definition, unalias to cancel the custom aliases.
Wildcard characters and redirects
Wildcard characters |
- LS *.txt* wildcard some arbitrary characters
- Ls?. TXT wildcard an arbitrary character
- ls [0-4].txt; LS [0-9a-za-z].txt wildcard 0, 1, 2, 3, 4 any of its names. txt all listed
- ls {0,2}.txt = ls [0,2].txt does not contain 1.txt
|
Input and output redirection |
- Cat 1.txt > 2.txt Front output redirects to the back, which will put the back of the rewrite
- Cat 1.txt >> 2.txt front output append to back
- LS aaa.txt. 2> a.txt Front Command error output redirect to back
- LS aaa.txt 2>> a.txt front Command error output append to back
- &> correct error output full redirect to Back, also support append
- Command >1.txt 2>2.txt the correct output and errors of a command are saved separately
- Wc-l < 1.txt "View 1.txt rows" to the right of the input redirect to the left of the command input, from right to left only left is the command.
|
Linux5.2 Shell based on