First, 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)
- also zsh, Ksh,
II, History
- History command The
is the most recently entered command history, and the command history is written to the current file in memory, and only once each time you exit the terminal normally, the command histories
- . bash_history
Command history files echo $HISTSIZE
Command History Max 1000
This setting can be modified in
/etc/profile
vim Etc/profile
If you want the history table to display a history command in the following command
histtimeformat= "%y/%m/%d%h:%m:%s"
only takes effect in the current command window when you execute it separately
If you want to make it permanent, add the command to the/ETC/PROFILE environment variable
Vim/etc/profilesource!$//Make environment variable effective
If you want the history file to be saved permanently
chattr +a ~/.bash_history
This time the file can only be appended cannot be deleted, ignoring 1000 restrictions
!!
To execute the previous command
!n
To execute the nth command in the history command
!word
Executes the last Word command in command history, where word can be replaced with any command
Iii. command Completion and aliases
tab, knock, Knock, double click.
A knock will automatically fill the command. If you have more than one command at the beginning, you'll need to double-tap to select from the list
Parameter completion, installation Bash-completion
yum install -y bash-completion
Reboot required after installation
Alias aliases give the command a name again
Alias restartnet= ' systemctl restart Network.service '
Each user has their own configuration alias file ~/.BASHRC
This file has a few default alias
Some other aliases are stored under the/etc/profile.d/directory
ls/etc/profile.d/
Custom alias put to ~/.BASHRC
Canceling aliases with Unalias
四、通配符
ls *.txt //列出所有的txt文件 ls ?.txt //列出文件名是一个字符的txt文件 ls [0-9].txt //列出文件名是1-9的txt文件 ls [13].txt //列出文件名是1或者3的txt文件 ls {1,2}.txt //列出文件名为1的txt文件和文件名为2.txt文件,如果有其中一个不存在,会提示
V. Input/Output redirection
cat 1.txt >2.txt //将前面命令的输出输入到后面的文件中(覆盖2.txt内容) cat 1.txt >> 2.txt //将前面命令的输出追加输入到后面的文件中(在2.txt中追加) ls aaa.txt 2>err //将前面命令的错误信息输入到后面的文件(覆盖) ls aaa.txt 2>>err //将前面命令的错误信息追加输入到后面的文件(不覆盖) ls {1,6}.txt &>999.txt //将正确和错误信息都输入到后面文件中 ls {1,6}.txt >999.txt 2>66.txt //将正确信息输入999.txt,错误信息输入66.txt wc -l < 1.txt //输出右边文件的文件行数(左边需要是命令,不可以是文件)
Linux Learning Notes (23) Shell Introduction, History command histories, command completion and aliases, wildcard characters,