Exercise 1:Print a line with only one numberRequirements: title, a text document with only a number of lines to print outReference Answer:#!/bin/bash# date:2018 March 16 f=/etc/groupline= ' wc-l $f |awk ' {print $} ' for L in ' seq 1 $line ' do n= '
function definition Format:It's a bit like JS, but the function keyword is optional in the shell.Such as:sum{ //Shell statement} function sum () { //Shell statement}Function Call Method:Sum parameter 1 parameter 2 ... Get function Parameters:
Exercise 1:Statistics Log size If we need to execute the script you wrote every hour. In the script to implement such a function, when the time is 0 and 12 points, you need to empty the file under directory/data/log/, notice can only empty the
Title requirements:Write a script to enter personal information/root/bin/information.sh, the requirements are as follows:1. Prompt the user to enter username (need to check the name of the character, the user name can not be blurred contains any of
Exercise 1:Enter a number to execute the corresponding commandRequirements: Enter a number and then run one of the corresponding commands. The commands shown are as follows: *cmd meau* 1-date 2–ls 3–who 4–pwd; when input 1 o'clock, run date, enter 2
1. PurposeCopy all files larger than 1M (customizable) in the/root directory to the/tmp/bakdir (customizable) directory, and you need to keep the directory structure.For example, the/root/reed.file file size is 12M and will be copied to
Exercise 1:Delete the letters in the textRequirements: Delete the line containing the letters in the first 5 lines of a text document and delete all the letters from 6 to 10 lines (file 1.txt, lines greater than 10 lines)Reference Answer:#!/bin/bash#
Nginx log will increase with the amount of traffic, the larger log will affect the analysis log when the analysis and processing, we can use the shell to the Nginx log timing segmentation, to weeks or days, for a long time log can be deleted
Crontab can execute a shell script and execute a series of Linux commands at a specified timeExample: Server administrator regularly backs up database data, logs, etc.DetailedCommon commands:Crontab–e //Modify the crontab file, if the file does
1. Variable assignment:NAME=LBG equals sign cannot have spaces name= "Lebron James" variable values have spaces in double quotes Echo ${name} with ${} More insurance shopt-s-O Nou Nset setting "Declare and use first"2. Cancel the variable:unset
The first line of the shell script illustrates the path to the interpreter: #!/bin/bashRun the script two ways: Use the bash command to run the shell file, or grant the script file execution permissions, you can directly execute the fileWhen the
Note Using expr:The operator and the number used for the calculation have at least one space around it, otherwise the errorWhen using multiplication sign, a backslash must be used to mask its specific meaning.An enterprise-class case study of
One step in writing a shell is to take a piece of text and process it.I. SED commandSed is a powerful streaming editor (stream editor for filtering and transforming text) that works perfectly with regular expressions, processing text line by row and
The first is to find the file name by using a-name parameter.Query for files ending in. txt, and files that begin with T :[Email protected]:~/test$ lsone.txt three.txt two.txt[email protected]:~/test$ Find/-name ' *.txt './two.txt ./one.txt./three.
Some bits and pieces of basics I. Understanding shell scriptsa) Related conceptsThe shell is a command interpreter that executes the commands and programs that the user enters in order (the command that encounters the sub-script, which executes the
Shell Script Fourth-common small script 1, the system process according to the size of memory consumption display out# PS-E-o "%c:%p:%z:%a"|sort-k5-nr2. The system process is displayed by CPU size# PS-E-o "%c:%p:%z:%a"|sort-nr or # PS aux--sort-rss3,
Summary
The attribute of an array is a set of identical data types, although the shell is a weak type, but we can also divide its array into 数据类型的数组 字符串类型的数组 two categoriesSeparating the shell array elements from each other 空格
$0, $? In Shell scripts? , $! , $, $ *, $ #, $ @, Etc.
$0 indicates the execution name of the program. The file name of the current script $ n indicates the nth parameter value of the program. n = 1 .. 9 $ * all parameters of this program. This
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service