echo [options] [Output CONTENT]
-E: Escape character that supports backslash control
Example: Echo-e "Hell\bo" → Output as "helo"
Echo-e "\x68\t\x65\t\x6c\n\x6c\t\x6f\t" → output hello (with format)
Echo-e "\e[1;34mthis is a blue\e[0m" → output blue font (this is a blue)
#30m = black, 31m= red, 32m= green, 33m= Yellow
#34m = blue, 35m= magenta, 36m= cyan, 37m= White
Script execution:
First: (Give execute permission)
①chmod 755 hello.sh
②./hello.sh
The second type: (Do not give execution permission)
①bash hello.sh
command aliases and shortcut keys:
alias→ viewing aliases for system effectiveness
Alias alias = ' original command ' #设定命令别名 (temporary effect)
Vim ~/.BASHRC #写入配置文件 (permanent) (source. bashrc→ Reload config file)
Unalias alias #删除别名 (Temporary entry)
ctrl+c→ forcing the current command to terminate
ctrl+l→ Clear Screen
ctrl+a→ cursor moves to the beginning of the command
ctrl+e→ cursor moves to the end of the command line
ctrl+u→ Delete from the cursor position to the beginning of the line
ctrl+z→ the command into the background.
ctrl+r→ Search in the history command
Historical commands:
History [Options]
-C: Empty history command
-W: Write History command in cache to history command to save file ~/.bash_history
History command saves 1000 by default and can be modified in/etc/profile
!n→ repeating nth History command
!! → Repeat the previous history command
! string → Repeat the last command that starts with the string
Output redirection:
Keypad /dev/stdin0 Standard input
Display /dev/stdout1 standard output
Display /dev/stderr2 standard error output
Command > file #以覆盖的方式 to output the correct output of the command to the specified file or device
Command >> file #以追加的方式 to output the correct output of the command to the specified file or device
Error command 2> file #以覆盖的方式, output the error output of the command to the specified file or device
Error command 2>> file #以追加的方式, output the error output of the command to the specified file or device
Command >> file 2>&1 #以追加的方式 to save the correct output and error output to the same file
Command &>> file #以追加的方式 to save the correct output and error output to the same file
Command >> file 1 2>> file 2 #把正确的输出追加到文件1中, append the wrong output to file 2
Enter redirection:
WC [options] [filename]
-C: Statistics of bytes
-W: Count the number of words
-L: Count rows
<<<
Sequential execution of MULTIPLE commands:
Command 1; command 2 #度命令顺序执行
Command 1 && command 2 #当命令1正确执行, command 2 does not execute
Command 1 | | Command 2 #当命令1执行不正确, command 2 does not execute
Example: Command && echo yes | | Echo no #命令正确执行输出yes, error execution output no
Pipe character:
Command 1 | Command 2 #命令1的正确输出作为命令2的操作对象
Wildcard characters:
? → Match an arbitrary character
*→ Match 0 or any number of any characters
[]→ matches any one of the characters in brackets
[0-9]→ matches a number in a number from 0 to 9
[^0-9]→ matches any one of the numbers in addition to 0-9
This article is from the "we_need_to_try" blog, make sure to keep this source http://liuxiao255.blog.51cto.com/10551403/1831745
The Shell Foundation of Linux Learning article