CTRL + A: Adjust the cursor to the beginningCtrl+e: Adjust cursor to endCtrl+u: Delete the command before the cursorCtrl+k: Delete the command after the cursorCtrl+r: Search A History list for a command "search for a History"Ctrl+l: Clear ScreenCTRL
1> file Comparison:-d filename checks if filename exists and is a directory-e filename checks if filename exists-F filename checks if filename exists and is a file-r filename checks if filename exists and is readable-s filename Check if filenmae
Case requirementsBatch build Linux users with shell scriptsImplementation requirements: Create user student1 to Student50, specify Group as student group! And each user needs to set a different password!Implementing scripts#!/bin/bashgrep ‘student‘ /
declaring functionsDemofun () { echo" This is my first shell function! " }Function name () {... function body}In the shell, arguments can be passed to a function when it is called. Inside the function body, the value of the parameter is obtained
View Catalogawk ' {if (!system ("test-d")) print $} 'Batch Quick Create user for in user{0.. Ten Do useradd $i echo123456passwd --stdin $i DoneUse the IF statement to determine#!/bin/bash# file Judgmentif[-E $1]; Then Echo "File
Integer numeric Operations use the expr command: You can only do integer operations and return the calculation results by default Format:Expr integer 1 operator integer 2 ...Integer values can be supplied with variables, giving the result of the
Function Description: Execute commands on multiple servers in bulk1 #!/bin/bash2 3 # ==========================================4 #function: Execute commands on multiple servers in bulk5 #method:./batch_cmd_manager.sh 6 #return: List of results
Function Description: Cleans the Messages history log file (Messages-date) under the/var/log/path, but does not clean the messages file itselfDependency requirements: The BC module is installed on the server1 #clean_logs.sh2 #!/bin/bash3 4 # ========
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]
Exception handlingYou can use the Try/except statement to catch an exception.The try/except statement is used to detect errors in a try statement block, allowing the except statement to catch exception information and handle it.If you do not want to
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
Requirements: Use the shell to customize a variety of personalized alarm tools, but the need for unified management, standardized management.Idea: Specify a script package that contains the main program, subroutine, configuration file, mail engine,
#!/bin/bash #Write a script#1. Set the value of the variable file to/etc/passwd#2. Say hello to each user in/etc/passwd and say what the ID is.#shaped like:#Hello,root,your UID is 0. FILE=/etc/passwd COUNT= ' Wc-l${file}| Cut-f1-d" "` forIinch'
I. Functions in the shellThe function is to organize a piece of code into a small unit, and give the small unit a name, when the code is used to call the name of the small unit directly.1. function formatfunction f_name() { command}The
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#
Script[[email protected] shell]# vim for1.sh#!/bin/bashfor i in `seq 1 6`do echo $idoneExecution results[[email protected] shell]# sh for1.sh123456Script[[email protected] shell]# vim for2.sh#!/bin/bashsum=0for i in `seq 1 6`do echo "$sum
One, for loopThe For loop structure is a very frequent loop structure used in daily operation and maintenance work.1. For loop specific format:for 变量名 in 循环条件; do commanddoneThe "loop condition" here can be a set of strings with numbers
# # #10个实战及面试常用的shell脚本
Some considerations before writing the script
1. Start with interpreter: #!/bin/bash pre>
2. Syntax indentation, using 4 spaces, more attention to the description
3. Naming rules:
First, Shell script introduction
The shell is a program written in C that is a bridge for users to use Linux. The shell is both a command language and a programming language.
The shell is a scripting language;
Can use logic
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