A summary of common methods for Linux shell commands

Source: Internet
Author: User
Tags linux shell commands

Date
# Take the day before
date-d ' 1 days ago ' +%y-%m-%d

Order, E-Name, set function: (alias)
Alias Ll= ' Ls-al '

Some special values
$$: (for this shell PID)
$!: Get the process pid of the subprocess, for example the Nohup command can get the PID
$: (? On??? The WAN of the sash? quiff?
$#: Number of parameters

$@: Representing "$1″" $2″ "$3″" $4″ "
$*: On behalf of "$1c$2c$3c$4″", where c. Beech refers to 糇 compromise?/p>

Declare
The numerical calculation is to use Declare-i sum=100+12
You can also use sum=$ ((100+12)) to calculate
[Root@www ~]# declare [-AIXR] Variable
????? /> BR-A: ⑨ Yan Ting? Variable's?? Knife, X-Guillotine, column (array)
-I: ⑨ Yan ting? Variable's?? A knife? x 檎?? Bottom (integer) type
-X: Usage? Export one cherry ⑨ Yan Xian variable?? The BR/>-r: ⒆?? Zhai O made? ReadOnly Type,??? Block 豢 kill Huan?? Jes, unset.

Array
var[1]= "Small min"
echo $ (var[1])

Delete/Replace character
echo ${path#/usr*:} #从前到后开始删除掉第一个符合条件的字符
echo ${path##/usr*:} #从前到后开始删除掉所有符合条件的字符
Or you can start at the back and replace the # number with the%
Echo ${PATH/USR/USR} #替换
Echo ${PATH//USR/USR} #替换所有

&& and | |
You can string together multiple commands, such as
ls./test/| | mkdir./test/#如果目录不存在, creating a

Judge
Note spaces must have [-e ' xxx '] when using brackets

Grammar

If ["$name" = = "Fatkun"]; Then
echo "hi! Fatkun "
elif [...]; Then
echo "..."
Else
echo "..."
Fi

What is the meaning of "y"?
1. In a??? N-Name "n-case" sentence? TEST-E filename Indicates whether there is
-e? "? N name "Does it exist?" Common
-F? "? N name "exists and?? n Case (file)? Common
-d? "? N name "Does it exist and is it a compliment?" (directory)? Common
B? "? N name "exists and is Ligularia?" Block device?
-C? "? N name "exists and is Ligularia?" Character device?
-S? "? N name "exists and is Ligularia?" The Socket? n case?
-P? "? N name "exists and is Ligularia?" FIFO (pipe)? n case?
-l? "? N name "exists and is Ligularia????? N?
2. In the case of n? Y, such as test-r filename, can you say no (but root ung s hin??)
-r?? Y?? n names exist and have a "can?" ?
W?? Y?? N Name exists and has "can??" ?
X?? Y?? n names exist and have a "can?"
-U?? Y?? Does n name exist and have "SUID"? Nuo yu
G?? Y?? Does n name exist and have "SGID"? Nuo yu
K?? Y?? Does n name exist and has "Sticky bit"? Nuo Yu
-S?? Y?? Does n name exist and Luo? n case "?
3.???? n the ratio of the case, such as: Test file1-nt file2
-nt (newer than) sentence? Whether File1 is newer than file2
-ot (older than) sentence? is file1 more than file2?
-ef sentence? File1? File2 is enshrined? n case, can be used in the sentence? Hard Link's decision. The main idea is to judge,???? Does n case all point to the same?? Inode Mile!
4.??? The judgment of N1-eq G, such as test N2
-eq?? Andy Sigh (equal)
-ne?? Withstand bad (not equal)
-GT N1 greater than N2 (greater than)
-lt N1 less than N2 (less than)
-ge N1 is larger than N2 (greater than or equal)
-le N1 is less than equal to N2 (less than or equal)
5. The material of the judgment string
Test-z string Determines whether the string is? 0? What if string? T? True
Test-n string to determine if the string is not? 0? What if string? T? False
?:-N can also be omitted
Test STR1 = str2 determine if str1 is equal to str2, and if so, t back? True
Test str1!= str2 determine if str1 is not equal to str2, if equivalent, t back? False
6. L-piece judgment, for example: Test-r filename-a-x filename
-A (and)??? R and R set up! For example Test-r file-a-x file,?t file with R? X? r, just back? True
-O (OR)??? R any one?? Was founded! For example, Test-r file-o-x file,?t file has R or X-r, you can go back? True
! The reverse phase?? B, like test! -X file,? File does not have X-r, back? True

Case syntax
Case $?? Have? Q in <==?? Word? Case,? The dam is embroidered with X-word?
"The first????? Hot quot; <== per????? Hot-ㄗh is surrounded by angry? P-word? t Tangyue ±ㄌ? )
Program Segment
;; <== per???? E. End use????? The points?? The Kip!
"The second????? Hot quot;
Program Segment
;;
*) <== last????? Jedi?? * 泶 硭 Peacemaker lu liling?? br/> does not contain the first????? Hot Chang C second????? Hot 莸 Sodium lu Liling, sash, br/> Exit 1
;;
Esac <== Most of the case? Tail! "Anti-????" Think about it!
While syntax
While [condition] <== is enclosed in the?? Que?? B is a fast sulphon br/> Do <==do is a circle?
Program paragraph
The done <==done is a circle?
For...do...done syntax
For Var in con1 con2 Con3 ...
Todo
Program Segment
Done
For ((i=1;i<100;i++));d o
Echo $i
Done
Replacement of soft chain
LN-SNF./hive-0.7.1/hive

Use grep and Gawk,xargs to kill
Xargs will turn each row of gawk into a kill parameter, such as Kill 1 2 3

Grep-v is excluded

Ps-ef|grep scott|grep-v Grep|gawk {' Print $1′}|xargs kill

SED command replaces text
Sed-i "s/oldstring/newstring/g" ' grep oldstring-l yourdir ' #在原文件修改
Sed "s/oldstring/newstring/g" file >file.new # output to other files
Tar
Tar--exclude=./xxx/cache--exclude=*/log/*-cvzf xxx_ ' date +%y-%m-%d_%h_%m '. tar.gz

Get Machine IP

/sbin/ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v Inet6|awk ' {print $} ' |tr-d ' addr: '

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.