Learn more about the character test of Linux and the practice of bash scriptingOne, character test options= =: Tests whether two strings are equal, equals true, and not equal to false.! =: Tests whether two strings are unequal, unequal to true, and equal to false.-N String: Tests whether the specified string is empty, NULL is true, and is not NULL for false.-Z String: Tests whether the specified string is not empty, is not empty, is true, and Null is
read file instead of the screen outputCommon Command options:P Print matching linesA newc instead of one lineD Delete Anchor rows replaces some parts of a row2.6.1sed-Example1. Displaysed-n ' 2p ' tmp.txt show only line 2ndsed-n ' 1,3p ' temp.txt print lines 1th through 3rdsed-n '/mov/' p temp.txt print lines with movie2. Deletesed ' 2d ' tmp.txt Delete line 2ndsed ' 3,d#x2032;tmp.txt#x5220;#x9664;#x7B2C;3#x884C;#x5230;#x6700;#x540E;#x4E00;#x884C;#xFF0C;">D′TMP.TXTBy deletingExceptThe3YesToMost
; Thenuserdel-r $USER [$DEBUG-eq 1] ECho "Delete $USER finished." else[$DEBUG-eq 1] echo "$USER not exist." Fidonefi Exercise: Write a script showlogged.sh, which uses the format: Showlogged.sh-v-c-h|--help where the-h option can only be used alone to display help information; the-C option displays the number of users logged on on the current system If you use the-V option at the same time, both the number of simultaneous users logged in and the information about the logged-on user are display
Guide
As we all know, system administrators need to be proficient in a scripting language, and so will the job requirements listed by the recruiting agencies. Most people think that Bash (or some other shell language) is easy to use, but some powerful languages (like Python) can bring you some other benefits.
First, we'll use Python's command-line tools, and we'll touch Python's object-oriented features (the second half of this article t
Often, when people refer to the "Shell scripting language", they are bash,ksh,sh or other similar Linux/unix scripting languages emerging in their minds. Scripting languages are another way to communicate with a computer. Users can move the mouse and click on a variety of objects, such as buttons, lists, marquee, and s
=" Picture 19.png "style=" Float:none; "alt=" wkiol1u7t4yw2jfiaadycgbc_5c930.jpg "src=" http:/ S3.51cto.com/wyfs02/m01/6b/f4/wkiol1u7t4yw2jfiaadycgbc_5c930.jpg "/>After rebooting, click Forward, then set the time, register (click Not registered) and then restart the system again after the final completion.650) this.width=650; "title=" Picture 20.png "style=" Float:none; "alt=" wkiom1u7tivcwj-naadxhox-2ri902.jpg "src=" http:/ S3.51cto.com/wyfs02/m01/6b/f8/wkiom1u7tivcwj-naadxhox-2ri902.jpg "width
fileYou can also connect many parameters.such as Sort-t ': '-K 3 testYou can think of it as something inside. xxx1:xxx2:xxx3:xxx4:xxx5means to sort the xxx3-T: Specifies a character to distinguish the key position-K:--key=pos1[pos1]. The sort starts with pos1, and if POS2 is specified, it ends at Pos2.| Redirects the output of the du command to the sort command.-r: Indicates descending order.Here is an example:4.3.21. grep [options] pattern [file]For example:grep t test//Search for text in test
Linux Scripting Learning
D: Delete rows that match the criteria
Sed ' 1,2d '/etc/fstab delete 1, 2 lines, show other rows
P: The line that displays the print fit condition
Sed '/^\//p '/etc/fstab matches the display, plus the original, there will be 2 duplicateSed-n '/^\//p/etc/fstab displays the line that matches the print
A: Add/string after the specified line
Linux View user Login system related commands and scripting (vii)View user log in System1.W shows who's logged in and what's being done2.who shows who logged in-R: Show System RunLevel3.sleep Sleep Command (sleep 5 sleeps 5 seconds after waking up)4.whoami display user name or UID5.last: Display/var/log/wtmp file showing user login history and System restart history-N 3: Displays information about the last
Linux Bash programming case statements and scripting (eight)1.case statement in the following format:Case variable inValue 1)Statement 1...;; Each branch statement ends with a semicolonValue 2)Statement 2...;;*) Other, equivalent if statement elseStatement 3...;;ESAC the entire case statement ends2 . Write a script that adds and deletes the user arbitrarily, with the following requirements:2.1: If the scrip
file is a script that is executed when the Linux system startsEdit the Inittab file (use the Vim/etc/inittab command to open the file)Example: Add a statement to the Inittab file to allow the system to execute a shell script file that checks the system disk when it starts checkdisk.shcheckdisk::once:/sbin/checkdisk.sh >/dev/console 2>1 indicates that this command is executed at each runlevel, if it is to be developed at the third run level: Checkdisk
:07Variables in shell scripts
You should use a variable instead when you use a string more frequently in your script and the string length is long
When using conditional statements, variables are often used?? If [$a-gt 1]; Then ...; Fi
When referencing the result of a command, replace it with a variable?? n=wc -l 1.txt
When writing scripts for user interaction, variables are also necessary?? Read-p "Input a number:" N; echo $n?? If you don't write this n, you can use $reply
No orders found.
128
Invalid exit parameter
128+x
Critical error for Linux signal x
130
Command terminated with CTRL + C
255
Exit status code out of bounds
Exit Exit command can specify exit status code, but not more than 255, otherwise it will be moduloCode 1-16[Email protected]:/data# cat Demo4 #!/bin/bashdateecho $?whoexit 5[email protected]:/data#./dem
/etc/crontab Add the following code: Here's an example of an hourly 26-minute execution: * * * * * root/home/**/wewang/autobackupmysql_qas.sh If executed at three O ' Day, then: XX 3 * * * root/home/**/wewang/autobackupmysql_qas.sh Case 2:redhat situation. ( that is, the currently used Linux system ) Copy the script you just edited to the appropriate directory
[Email protected]***** wewang]# CP autobackupmysql_qas.sh/etc/cron.da
Scripting for Bash programming until statements and formatted hard disk partitions in Linux (10)1. Summary of circular statement structure1.1.while Statement Enter the Loop statement when the condition is metWhile condition; DoStatementDone1.2.until Statement Enter the Loop statement when the condition is not satisfieduntil conditions; DoStatementDone1.3.for variable in list; DoLoop bodyDone1.4.for ((expres
Scripting for the special use of the while statement under the Linux Bash Program (10)1. Loop control:Break: Interrupts the entire loop statement, which is the statement following the execution of the script after exiting the loopContinue: Interrupt the current cycle, advance to the next round cycleExit: End Script Run2.while dead Loop, that is, when you do not know how many times the loopFormat: while:; Do
Previous Edit CommandA: Append data after the current cursorO: The next line of the cursor inserts dataDW Delete a Wordd$ Delete to end of lineDD: Delete Row, 5dd delete 5 rowsThe use of backspace and delete keys in normal mode is not recognized.10.1.4 Copy and pasteDD can be pasted with p after deletion.The copy command is Y,YW copy a wordy$ Copy to end of lineThen use p to paste10.1.5 Find Replacement: s/old/new/g a line command to replace all old, which is replaced only on one line: N,ms/old
-be-sustained by perpetual neglect of many and other things. Robert Louis Stevenson (1850-1894)
[Email protected]:~/shell/26zhang$
Note this:#grep "$ (date +%b '%-d, '%Y)"-A2 |Since my Ubuntu is in Chinese, I have not been searching for November. I'm going to replace it with this one, only 28, 2017.grep ", $ (date +%y)"-a2 | # Xcy AddIt would have been like this grep "$ (date +%-d, '%Y)"-A2 | # xcy Add, don't know why my date is 29. And the site is 28. May be related to the U.S. website.26.3
Requirements Description :Linux environment in the creation of users, involves the modification of the user's password, generally through the passwd command to modify, need to confirm multiple times, here consider a command directly to modify the passwordThere is no way to interact. This record.Operation Process :1. Use the echo command to combine the passwd command to achieveEcho " mytest " passwd -- for user mytest. passwd: All authentication token
, which is represented as a local variable. such as local temp=1 .Example 3. Array Parameterstest3.sh#!/bin/bash Span class= "hljs-comment" ># trying to pass a array variable function testit {local newarray # use ' local ' define a local variable newarray= (' echo " the NewArray value is ${newarray[*]} "}myarray= (1 , 2 , 3 , 4 , 5 ) echo "the original array is:${ Myarray[*]} " testit $myarray Test:sh test3.shOutput:The original array is:1,2,3,4,5The NewArray value is 1,2,3,4,5Example
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.