First,ShellFour The Swordsman (grep)grep fetch rowsRegular Expressions:
[0-9] denotes character match 0-9{1,3} indicates that the number of matching characters is less than 3.
Example one:
[email protected]
Create a TXT file in the "/home/hadoop/" directory of your local Linux file system, where you can enter some words.mkdir hadoopcd Hadooptouch Test.txtgedit test.txt
To view the file location locally (LS)Ls-al
Displaying the contents of a file
Recently in the shell script, found some shell strings of the Sao operation, can improve efficiency.String Read
${var}: Value of variable var
${var-default}: If Var is not declared, the value of Var is $default
${var:-default}: If
Pipe character
| Function: The output of the preceding command is given to the following command job control
CTRL Z pauses a task
[[email protected] ~]# vim 1.txt [1]+ 已停止 vim 1.txt[[email protected] ~]# vim 2.txt [2]
Pipe character and job control
| Give the result of the previous command to the following command processing.[[email protected] ~]# cat 1.txt |wc -l 统计行数5[[email protected] ~]# cat 1.txt |grep ‘aaa‘aaaa 剪切出aaa的行
CTRL Z pauses a task,
When the shell initializes the installation script, it is necessary to install some RPM packages from the network, all of which need to detect the smoothness of the network first.Code#检测网络链接 &&FTP upload Datafunctionnetworkandftp () {#超时时间 timeout=5#
First, special symbols' * ' wildcard character, any of any characters'? ' any one character' # ' comment characters' \ ' de-semantic characters' | ' pipingThe prefix of the ' $ ' variable'!$ ' combination, regular inside means end'; ' multiple
Write a script in the Linux environmentFrom the keyboard to let the user enter several files, the script can archive this several files into a file:1. First introduce the CASE statement formatCase SWITCH invalue1)Statement...;;value2)Statement...;;*)
Customizing a function for printing function parameters[[email protected] shell]# vim fun1.sh#!/bin/bashpri(){ echo "第一个参数为 $1" echo "第二个参数为 $2" echo "文件名为 $0" echo "总共有$#个参数" }pri a b #调用函数Execution
1. The concept of variables: variables are stored in the program of the user's memory space, the variable name is the address of this memory space, the value of the variable is stored in the computer memory. Variable definition: It is simple to
First, Shell introductionShell scripting is an essential part of everyday Linux system management, not a shell, not a qualified administrator.The shell is the intermediate medium that the system interacts with the computer hardware, a system tool.
Requirements: Remove the IP field from the log and sort the statistics. General use awk command if the IP address is the first field thenawk ' {print '} ' filename |sort |uniq-c|sort-nrWhat if it's not the first field and there are several
Locate command1.locate filenameFuzzy match as long as the file name contains the keyword can beNon-real-time lookup, faster than find.Rely on index database/var/lib/mlocate/mlocate.dbAutomatically run once a day to update the database.UpdateDB
Test condition judgment# symbol [] equals test commandTen 5 # Judging the size of echo $? # View the previous sentence The test command returns the status "hello" # To determine if the string length is 0[$ 0"success" | |
1. Like other languages, the shell can also contain external scripts, which makes it easy to encapsulate some common code as a standalone fileExample: The testshellfileinclude.sh script is as follows:the #!/bin/Bash#shell file contains the following
Arrays are not used very often in the shell, but are very useful, let's take a look at some of the uses of arrays in the shell:
Define array a= (1 2 3 4 5); Print array echo ${a[@]}The contents of the array can be either numbers or letters, as
ArrayAn array is an ordered sequence of elements. If a collection of variables of the same type is named, the name is an array name. Each variable that makes up an array is called the component of an array, also known as an element of an array,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.