The basic features of bash:Command completion:The shell program receives a request from the user to execute the command, and after the analysis is completed, the leftmost string is treated as a command;Command Lookup mechanism:Find internal commands;
The difference between source test.sh and./test.sh is that source can use the variables of the test.sh script after the script is executed, and./test.sh, its variables can only be used in scripts.Variables can be divided into global variables, local
Organized a number of shell-related exercises, recorded here.1. Please follow the date format xxxx-xx-xx to generate a daily file, for example: The file generated today is 2013-09-23.log, and the use of the disk is written to this file.1 #!/bin/bash2
Script 1 Stop Lampp#!/bin/bash#set-XV Open debug mode?Count= ' Ps-ef|grep lampp|grep-v "grep" |wc-l ' # "" is the TAB key that holds down shift to appear ~ symbol, excluding the command count lines of grep itselfIf [$count-GT 0] # greater than one
Shell in && | | Usage && operator: command1 && command2 && Left command (Command 1) returns True (that is, returns 0, successfully executed) after,&& The command on the right (command 2) can be executed, in other words, "If this command executes
CMD is also a shell of Shell windowns.View files and folders dirmkdir * * * Create folder Rd* * Delete folder (should have parameters, recursion, etc.)Ctr+c Abort Commandcd>***.** Creating a file del filename Type + relative path view
#!/bin/bashread-p "Please enter the number of start:" Minread-p "Please enter the number of terminations:" Maxif [$min-gt $max]thenecho "Start number is greater than the number of terminations! "Elseecho-n" random number: " ; expr $ (date +%n)% $[
1. Shell basic format, variable# Add an interpreter to the shell script #! /bin/bash# Print out Hello world with a script#! /bin/bashecho "Hello World"ExitParameters: A parameter is an entity that stores real values that are typically referenced in
Technorati tag: Shell,df,sed,awk -Monitor System statistics
Monitor disk free space
Disk Resource Usage
Monitor CPU and Memory usage
-Perform a backup
Archive data files
Offline Storage of Backup files
Enter 2 numbers (x, y) if x equals Y, the output is z=x+y, if x is greater than Y, the output is z=x-y, otherwise the output z=x+yVI number2.sh#!/bin/bash#written by Lizheng#about Panduanecho "Please enter the number"Read XRead Yif test $x-eq $yThen
The company now needs to make regular backups of the existing servers and place the backup files in the NAS being used;For the efficiency of backup, we also need to filter the backup files and exclude some files with suffix names.The implementation
Before modifying the file name#!/bin/bask#for A in $ (ls/etc/yum.repos.d/centos*);d oif [$a! = '/etc/yum.repos.d/centos-media.repo '];then #CentO The S-media.repo file name does not modify the MV $a $a. bak
1. Batch generation of random character file name casesUse the For loop to bulk create 10 HTML files in the/sixijie directory, where each file needs to contain 10 random lowercase characters plus a fixed string sxj, with the following name examples:[
#!/bin/bashecho "**********argument**********"Echo Script Name: $Echo First argument $echo second argumentecho num of argument $#echo all argument [email protected]#functionEqual (){Case $ in$)return 0;;*)Return 1;;Esac}#ifecho "**********test if****
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