Shell special symbol Cut command:
1, * any arbitrary character (this is a wildcard character)
2,? Any one character
3. # comment Characters
4, \ de-semantic characters
5, | Pipe character
Several commands related to pipelines:
1, cut split,-D delimiter-f specifies the number of characters,-C,
Example:
[[Email protected] ~]# cat /etc/passwd |headroot:x:0:0:root:/root:/bin/bashbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/ Var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x : 7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/ Nologin[[email protected] ~]# cat /etc/passwd |head -2root:x:0:0:root:/root:/bin /bashbin:x:1:1:bin:/bin:/sbin/nologin[[email protected] ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1rootbin[[email protected] ~]# cat /etc/ passwd |head -2 |cut -d ":" -f 1,2root:xbin:x[[email protected] ~ ]# cat /etc/passwd |head -2 |cut -d ":" -f 1-3root:x:0bin:x:1[[ email protected] ~]# CAT /ETC/PASSWD |HEAD -2 |CUT -C 4T:
Sort_wc_uniq command:
2. Sort sorted,-N numerically sort-R reversed-T delimiter-kn1/-kn1,n2
Examples are as follows:
[Email protected] ~]# sort/etc/passwd (Sort by ID number, number, letter, etc.) adm:x:3:4:adm:/var/adm:/sbin/nologinaminglinux:x:1002:1002 ::/home/aminglinux:/bin/bashaming:x:1000:1005::/home/aming:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologinchrony:x : 997:995::/var/lib/chrony:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologindbus:x:81:81:system Message bus:/ :/sbin/nologinftp:x:14:50:ftp User:/var/ftp:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologin
3, WC-L statistics number of rows-m statistical characters-W statistics
Example:
[[email protected] ~]# wc-l 1.txt22 1.txt[[email protected] ~]# wc-m 1.txt450 1.txt[[email protected] ~]# wc-m 2.txt0 2 . Txt[[email protected] ~]# wc-w 2.txt0 2.txt
4, Uniq to weight,-c statistics row number
Use the Uniq command alone to go heavy, only in the list of the same upper and lower sequence to go to the weight, example:
[[email protected] ~]# vim 2.txt[[email protected] ~]# cat 2.txt123abc 111,222123abc121[[email protected] ~]# uniq 2.txt No sequence is the same and cannot be weighed. 123ABC 111,222123abc121[[email protected] ~]# vim 2.txt//change number sequence [[email protected] ~]# cat 2.txt123abc 111,222123abc112[ [Email protected] ~]# uniq 2.txt//de-weight same number 123abc 111,222123ABC12
The sort command is used to sort the first, then go to weight, calculate the number of repetitions, example:
[[email protected] ~]# sort 2.txt//auto sort 2.txt inside text list 111231232abcabc 111,222[[email protected] ~]# sort 2.txt |uniq Go to weight 11232abcabc 111,222[[email protected] ~]# sort 2.txt |uniq-c//Count repetitions 2 1231 ABC1 ABC 111,222
Tee_tr_split command:
5, tee and > similar, redirect at the same time also on the screen display
Example:
[email protected] ~]# cat A.txt[[email protected] ~]# sort 2.txt |uniq-c |tee a.txt2 [1231] ABC1 ABC 111,222[[email Protected] ~]# cat A.TXT2 1231 ABC1 ABC 111,222[[email protected] ~]# sort 2.txt |uniq-c |tee-a a.txt//tee Plus-a Yes Add 2 1231 ABC1 ABC 111,222[[email protected] ~]# cat A.txt2 (1231) ABC1 ABC 111,2222 (1231) ABC1 ABC 111,222
6, TR replacement character, tr ' a ' B ', case replacement TR ' [A-z] ' [A-z] '
Example:
[Email protected] ~]# echo "Aminglinux" |tr ' [al] ' [al] ' Aminglinux[[email protected] ~]# echo "Aminglinux" |tr ' [A-z] ' [A-z] ' aminglinux[[email protected] ~]# echo "Aminglinux" |tr ' [A-z] ' 1 ' 1111111111
7, split cut,-B size (default unit byte),-L line number (cut log, two usage)
Use the command:
Split-b 1000m Bigfilesplit-l Bigfile
Example:
[[email protected] test]# lsa.txt[[email protected] test]# split -b 100k a.txt[[email protected] test]# lsa.txt xaa xab xac[[ Email protected] test]# du -sh *256ka.txt100kxaa100kxab52kxac[[email protected] test]# rm -f x*[[email protected] test]# split -b 100k a.txt abc[[email protected] test]# lsabcaa abcab abcac A.txt[[email protected] test]# split -b 100k a.txt abc. [[email protected] test]# lsabcaa abc.aa abcab abc.ab abcac abc.ac a.txt[[email protected] test]# rm -f abc*[[ email protected] test]# split -l 1000 a.txt[[email protected] test]# ls -l Total dosage 516-rw-r--r--. 1 root root 257421 11 month 17 20:00 a.txt-rw-r--r--. 1 root root 42094 11 month 17 20:04 xaa-rw-r--r--. 1 root root 44424 11 month 17 20:04 xab-rw-r--r--. 1 root root 40244 11 month 17 20:04 xac-rw-r--r--. 1 root root 40202 11 Month 17 20:04 Xad-rw-r--r--. 1 root root 34871 11 Month 17 20:04 xae-rw-r--r--. 1 root root 39403 11 month 17 20:04 xaf-rw-r--r--. 1 root root 16183 11 Month  17 20:04 XAG[[EMAIL PROTECTED] TEST]# WC -l *6495 a.txt1000 xaa1000 xab1000 xac1000 xad1000 xae1000 xaf495 xag12990 Total Dosage
Under Shell special Symbols:
1, $ variable prefix,!$ combination, regular inside represents the end of the line
2. Multiple commands written to one line, separated by semicolons
[email protected] ~]# ls 1.txt; Wc-l 2.txt1.txt7 2.txt
3, ~ User home directory, followed by regular expression to indicate a match
4, & placed behind the command, will throw the command in the background
5, > >> 2> 2>> &>
>: Correct redirection will overwrite the previous file.
>>: Append redirect, append content to correct output.
2>: Error redirection
2>>: Append error redirect
&>: Indicates correct and error output redirection
6, [] One of the specified characters, such as [0-9],[A-ZA-Z],[ABC]
7, | | And &&, used between commands.
|| : Indicates or means that when two commands are executed simultaneously, if the first command executes unsuccessfully, the second command executes, and if the first command succeeds, the second command is not executed, as shown in the following example:
[[email protected] ~]# ls 1a.txt | | Wc-l 2.TXTLS: Unable to access 1a.txt: No file or directory 7 2.txt[[email protected] ~]# ls 1.txt | | Wc-l 2.txt1.txt
&&: When two commands are executed simultaneously, the following command is executed if the previous command executes successfully, otherwise it is not executed.
Examples are as follows:
[[email protected] ~]# ls 1.txt && wc-l 2.txt1.txt7 2.txt[[email protected] ~]# ls 1a.txt && wc-l 2.txtl S: Unable to access 1a.txt: No file or directory
Experiment:
[[email protected] ~]# ls111 1_heard.txt.bak 1.txt 234 3.txt aa.txt anaconda-ks.cfg test123 1_sorft.txt.bak 1.txt.bak 2.txt 456 aming2 bb.txt Introduction to the Smart Cloud Platform (ppt template). pptx[[email protected] ~]# [ -d aminglinux ] | | mkdir aminglinux[[email protected] ~]# ls111 1_heard.txt.bak 1.txt 234 3.txt aa.txt aminglinux bb.txt Smart Cloud Platform Introduction (PPT template). pptx123 1_ sorft.txt.bak 1.txt.bak 2.txt 456 aming2 Anaconda-ks.cfg test[[email protected] ~]# [ -d aminglinux ] && mkdir aminglinuxmkdir: Unable to create directory " Aminglinux ": file already exists [[email protected] ~]# [ -d aminglinux ] | | mkdir aminglinux
Explain:
[-D Aminglinux]: Determine if a directory exists.
This article is from the "Gary Blog" blog, please be sure to keep this source http://taoxie.blog.51cto.com/10245493/1982893
Linux cut, Sort_wc_uniq, tee_tr_split commands and some special symbols introduced