today accidentally hit the home directory Delete command, although finally for a variety of reasons did not delete, but the home directory, many files and directories are deleted, and the command line does not display the current user and path.
1.8 using Aliases
aliases in Linux are the equivalent of shortcuts in Windows, and using aliases can save users from having to enter a long sequence of commands.
1.8.1 Creating temporary aliases (shortcuts)alias new_command=‘command
#!/bin/bash while:do neterror=$ (/bin/netstat-a | GREP-CW "close_wait") echo "Get TCP netstate ' LISTEN ' num ber cuccessful! " echo "Neterror" $neterror if [$neterror-gt "]; then echo" too much net Error,system would reboot
1.5 using the shell for mathematical operationsIn any programming language, arithmetic operations are essential, and the shell is no exception.1.5.1 arithmetic operations using Let, (()), and []
You can use the normal variable assignment
Tenth lineHow would you print just the 10th line of a file?For example, assume. has the file.txt following content:Line 1Line 2Line 3Line 4Line 5Line 6Line 7Line 8Line 9Line 10Your script should output the tenth line, which is:Line 10[Show hint]Hint:
1.3 Playing variables and environment variablesvariables are an essential part of any programming language and are used to store variables of various types. Scripting languages are mostly weak type languages (dynamic languages), meaning that when
Use Whil for if to print a prime number less than 100#!/bin/bash#author Alvin#version 1.0.0#test for 1-100 Zhishua=2While [$a-le 100];DoZ=1for ((j = 2; $j If [$ ($a% $j))-eq 0];thenZ=0BreakFiDoneIf [$z-eq 1];thenEcho-ne $a "\ T"FiLet A+=1Done2 3 5 7
Special variables: $#the number of arguments passed to the script; $*displays all parameters passed to the script in a single string. Unlike positional variables, this option can have more than 9 parameters; $$the current process
For loop:Used in the shell for looping. Similar to for in other programming languages, but somewhat different. The For loop is the most common syntax structure in bash.Common format Format OneFor variableDoStatementDoneFormat TwoFor variable in
Test command usage:1) Judgment expressionif test (expression is true)if test! An expression is falsetest expression 1–a expression 22 expressions are truetest expression 1–o expression 22 expressions have a true2) Judging the stringtest–n String
#!/bin/bash## 1, check whether the current user's identity has permissions# 2, check if there is a Yum source, if there is no need to create a Yum source configuration file# 3, install DHCP, if already installed, we can first remove and then install,
1, log structure/opt/online/{123com,abccom}/log/online[1-9]/[a-z]2, variable description # Whether to turn on the compression function (0: OFF, 1: on; If the compression function is turned off, the Compressdayn is not valid) Needcompress=1 Delete 14
Linux operating system can be divided into shell and kernel two parts, kernel is the kernel, provides the core functions of the operating system. The shell is the shell, which is connected to the kernel (kernel) and the user. This means that the
1. Shell FeaturesOrder history!! !$!n! characterTab key to complete file path or commandAlias a= "B" Unalias AWildcard * Matches 0 or more characters? Match one characterInput/Output redirection >,>>,,2>>Pipe characterJob Control CTRL + Z jobs FG BG2
This script parses the log of the Nginx load balancer:#!/bin/bashif [ $# -eq 0 ]; then echo "Error:please specify logfile. " EXIT0ELSELOG=$1FIIF[!-F$1] ; then echo "Sorry,sir. i cat ' T find this apache log file, pls try again! " exit 0
The default value in the shell is decimal, so how are binary, octal, and hexadecimal represented?Method 1: Use the prefix.0 begins with octal, and 0x starts with hexadecimal.As follows:#-----------------------------/chapter4/ex4-35.sh----------------
Today, when we look at the/etc/init.d/nginx script, we find that there is a lot of behavior in the script (the space name of the dot). For example, a few lines of file start:if [-r/etc/default/nginx]; Then
Several methods of shell script execution, shell scriptYou can execute shell scripts in the following ways:
1. The relative path method must be cd to the script path first.
[Root @ banking tmp] # cd/tmp [root @ banking tmp] #./ceshi. sh script
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