8.1:shell Introduction:
The shell is a command interpreter that provides interaction between the user and the machine, supports specific syntax, supports logical judgments, loops, and each user can have his or her own shell:
The CentOS default shell is bash (Bourne Agin shell): In fact, to commemorate the creator of SH Bourne this user:
There are also common zsh (Power-shell) Ksh (Korn-shell): The supported features are relatively small:
8.2: The Command history: Historical
Commands that users use in the system are saved and saved in the current user's home directory:
History Command
Syntax: history [-c]
-c:=clear clears the in-memory command and cannot delete the history command in the configuration file
[Email protected] ~]# history
1 ls
2 ls/tmp/
3 ls/boot/
4 ls/
5 dhclient
......
[Email protected] ~]# ls/root/.bash_history/root/.bash_history history's home Directory
Show used command history, save 1000 used commands by default (note: This order needs to be in a normal shutdown operation in the case of 1000 life)!
History Environment Variables
[Email protected] ~]# echo $HISTSIZE 1000
This variable determines the number of commands saved by the command history.
Edit its configuration file
[Email protected] ~]# vim/etc/profile ...
Hostname= '/usr/bin/hostname 2>/dev/null '
histsize=1000 ...
[[email protected] ~]# echo $HISTSIZE 1000[[email protected] ~]# source/etc/profile[[email protected] ~]# echo $HISTSIZE 20 00
Search the keyword "HIST" to find ' histsize=1000 ', change its number here, save exit, and then execute the command ' source/etc/profile ' to refresh the profile before it takes effect.
[[email protected] ~]# history
1 2017/06/28 18:50:11 history 2 2017/06/28 18:51:32 echo $HISTTIMEFORMAT 3 2017/06/28 18:51:43 histtimeformat= "%y/%m/%d%h:%m:%s"
4 2017/06/28 18:51:45 echo $HISTTIMEFORMAT 5 2017/06/28 18:52:32 history
span>
Assign a value directly to ' Histtimeformat ', but this format only applies to the current terminal. If you want to use it for all users, you need to write it to the history profile and take effect after the refresh.
[Email protected] ~]# vim/etc/profile ...
Hostname= '/usr/bin/hostname 2>/dev/null ' histsize=1000histtimeformat= "%y/%m/%d%H:%M:%S" ...
Save Exit!
[Email protected] ~]# Source/etc/profile
[Email protected] ~]# chattr +a ~/.bash_history
Use file special permissions to configure ' A ' permissions for '. Bash_history ' files (can only be appended, not deleted), limited to normal shutdown operations.
'! ' Command
[Email protected] ~]# W ...
[[email protected] ~]#!! W
......
Eg:
[Email protected] ~]# history
1 2017/06/28 18:50:11 history 2 2017/06/28 18:51:32 echo $HISTTIMEFORMAT 3 2017/06/28 18:51:43 histtimeformat= "%Y /%m/%d%h:%m:%s "
4 2017/06/28 18:51:45 echo $HISTTIMEFORMAT 5 2017/06/28 18:52:32 History
[Email protected] ~]#!4echo $HISTTIMEFORMAT
%y/%m/%d%h:%m:%s
[[email protected] ~]#! histhistsize=1000
8.3 command completion and aliasesCommand Completion tab
Press TAB to complete a command or parameter (need to install package Bash-completion, restart the system); Press two tab to display all commands or filenames that begin with a letter.
alias Command
Syntax: alias [command alias]=[specific command] set aliases
Alias: Unalias [Command alias]
Enter alias directly to display all aliases for the system:
[[email protected] ~]# aliasalias 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 ' [[email protected] ~]#
[email protected] ~]# cat! $cat. bashrc#. bashrc# User specific aliases and Functionsalias rm= ' rm-i ' Alias cp= ' Cp-i ' alia S mv= ' mv-i ' # Source global definitionsif [-F/ETC/BASHRC]; Then
. /etc/bashrcfi[[email protected] ~]# ls/etc/profile.d/256term.csh colorgrep.sh lang.sh qt-graphics System.sh which2.sh
256term.sh colorls.csh less.csh vim.csh
bash_completion.sh colorls.sh less.sh vim.sh
COLORGREP.CSH lang.csh qt-graphicssystem.csh which2.csh
8.4 Wildcard Characters
The wildcard ' * ' stands for 0 or more arbitrary characters
Wildcard characters '? ' Represents an arbitrary character
Brackets ' [] ', ' ls [0-9].txt ' means any. txt file within the 0-9 interval
Curly braces ' {} ', ' ls {1,2,3}.txt ' means any. txt file in parentheses
input and output redirection
" >,>>,<,2>,2>> "
' > ': Output redirection
' >> ': Append redirect
' 2> ': Error redirection
' < ': Enter redirect
Use the ' > ' command to delete the contents of the original file.
[[email protected] tmp]# echo adaixuelinux > 1.txt [[email protected] tmp]# cat 1.txtadaixuelinux
[[email protected] tmp]# echo Adaixu > 1.txt[[email protected] tmp]# cat 1.txtadaixu#####################################[[email protected] tmp]# echo Adaixu >> 1.txt[[email protected] tmp]# cat 1.txtadaixu
Adaixu#####################################[[email protected] tmp]# lsaaa-bash:lsaaa: Command not found
[[email protected] tmp]# lsaaa 2> 2.txt[[email Protected] tmp]# cat 2.txt-bash:lsaaa: Command not found
Input redirection: Must be directed to (< left) under one command
[[email protected] tmp]# wc-l 1. TXT "wc-l" This command is used to view the number of file lines 2 1.txt
[[email protected] tmp]# ls {1,2}.txt aaaa.txt > 1.txt 2> 3.txt[[email protected] tmp]# cat 1.txt1.txt2.txt
[[email protected] tmp]# cat 3.TXTLS: Unable to access aaaa.txt: No file or directory
Description: use the LS command to view {1,2}.txt aaaa.txt,1.txt and 2.txt files exist, can use LS to view, Aaaa.txt does not exist, using LS view will error, ' > 1.txt 2> 3. TXT ' means to save the correct information to 1.txt and save the error message to 3.txt.
This article is from the "_de blog" blog, be sure to keep this source http://yuanhaohao.blog.51cto.com/7714752/1982188
Shell Introduction and basic usage