Linux Centos7 Shell Special symbols, cut commands, Sort_wc_uniq commands, tee_tr_split commands, Shell special symbols

Source: Internet
Author: User
Tags chrony

I. Shell special symbol, Cut command

* Any character

[Email protected] ~]# Ls/tmp/*.txt
/tmp/1.txt/tmp/2.txt/tmp/q.txt
[Email protected] ~]#

? Any one character

[Email protected] ~]# Mkdir/tmp/test1
[Email protected] ~]# Touch/tmp/test1
[Email protected] ~]# ls-d/tmp/test?
/tmp/test1
[Email protected] ~]#

#注释字符

[Email protected] ~]# sdx=233 #assa
[Email protected] ~]# echo $SDX
233
[Email protected] ~]#

\ de-Semantic characters

[Email protected] ~]# ls-d test\*
LS: Unable to access test*: No file or directory
[Email protected] ~]#

| pipe character, multiple commands available behind the pipe

[email protected] ~]# cat 1.txt |wc-l

Cut is used to intercept a field, the format cut-d ' separator character ' [-CF] n N represents a number

-D: followed by delimited characters, separated by single quotation marks

-C: followed by the first few characters

-F: Next to the first few blocks

[Email protected] ~]# cat/etc/passwd |head print out Files
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Operator:x:11:0:operator:/root:/sbin/nologin
[Email protected] ~]#
[Email protected] ~]#cat/etc/passwd |head-2 |cut-d ":"-F 1 intercept the first 2 lines 1th
Root
Bin
[Email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-FIntercept 1th and 2 of the first 2 lines
Root:x
Bin:x
[[email protected] ~]# cat/etc/passwd |head-2 |cut-d ":"-F 1-3Intercept first 2 lines--to 3
root:x:0
Bin:x:1
[Email protected] ~]#

[[email protected] ~]# cat/etc/passwd |head-2 |cut-c 4 intercept the first 2 lines to specify a 4th character
T
:
[Email protected] ~]#

Second, sort, WC, uniq command

Sort order, format sort [-t delimiter] [-KN1,N2] [-nru] N1, N2 for numbers.

-T back and delimiter

-n means sorting with pure numbers

-R indicates reverse ordering

-U means to repeat

The-KN1,N2 indicates that the N1 interval is sorted to the N2 interval and can be written only-kn1, that is, the N1 field is sorted

[Email protected] ~]# sort/etc/passwd |head-2 |cut-c 4
:
:

[Email protected] ~]# SORT/ETC/PASSWD
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Chrony:x:998:996::/var/lib/chrony:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Davery:x:1000:1003::/home/davery:/bin/bash
Dbus:x:81:81:system message Bus:/:/sbin/nologin
Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin
Games:x:12:100:games:/usr/games:/sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Nobody:x:99:99:nobody:/:/sbin/nologin
Operator:x:11:0:operator:/root:/sbin/nologin
Polkitd:x:999:997:user for Polkitd:/:/sbin/nologin
Postfix:x:89:89::/var/spool/postfix:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Sshd:x:74:74:privilege-separated Ssh:/var/empty/sshd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
SYSTEMD-NETWORK:X:192:192:SYSTEMD Network Management:/:/sbin/nologin
Uaer1:x:1001:1004::/home/uaer1:/bin/bash
User2:x:1002:1005::/home/user2:/bin/bash
User3:x:1006:1006::/home/user3:/bin/bash
User4:x:1007:898::/home/user4:/bin/bash
User6:x:1008:898::/home/user6:/bin/bash

Default According to ABCD ... Sort

[Email protected] ~]# head/etc/passwd >> 0.txt
[Email protected] ~]# sort 0.txt
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Operator:x:11:0:operator:/root:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Sync:x:5:0:sync:/sbin:/bin/sync
[Email protected] ~]#

[[email protected] ~]# head-n5/etc/passwd|sort  
adm:x:3:4:adm:/ Var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Lp:x : 4:7:lp:/var/spool/lpd:/sbin/nologin
Root:x:0:0:root:/root:/bin/bash
[[email protected] ~]#

[[email protected] ~]# head-n5/etc/passwd |sort-t:-k3-n third block in ascending order of numbers
Root:x:0:0:root:/root:/bin/bash
Bin:x:1: 1:bin:/bin:/sbin/nologin
Daemon:x:2: 2:daemon:/sbin:/sbin/nologin
ADM:X:3: 4:adm:/var/adm:/sbin/nologin
LP:X:4: 7:lp:/var/spool/lpd:/sbin/nologin
[Email protected] ~]# ^c

[[email protected] ~]# head-n5/etc/passwd |sort-t:-k3-n-R   &nbs P the third chunk is sorted by number
Lp:x: 4 : 7:lp:/var/spool/lpd:/sbin/nologin
adm:x:< Span style= "font-size:18px" > 3 : 4:adm:/var/adm:/sbin/nologin
Daemon:x: 2 : 2:daemon:/sbin:/sbin/nologin
Bin:x: 1 : 1:bin:/bin:/sbin/nologin
Root:x: 0 : 0 : Root:/root:/bin/bash
[[email protected] ~]#

[[email protected] ~]# sort-n 0.txt   from the first letter followed by the ASCII value of the comparison, and finally in ascending order
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/ Sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Mail:x:8:12: Mail:/var/spool/mail:/sbin/nologin
Operator:x:11:0:operator:/root:/sbin/nologin
root:x:0:0:root:/root:/ Bin/bash
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Sync:x:5:0:sync:/sbin:/bin/sync
[[email  Protected] ~]#

[[email protected] ~]# sort-nr 0.txt Reverse Sort
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Halt:x:7:0:halt:/sbin:/sbin/halt
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Bin:x:1:1:bin:/bin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin

WC command

Number of lines, characters, or words used to count documents

-L count rows

-M statistic characters

-W Statistic Word number

[Email protected] ~]# wc-l/etc/passwd
25/etc/passwd
[Email protected] ~]# wc-m/etc/passwd
1092/etc/passwd
[Email protected] ~]# wc-w/etc/passwd
33/etc/passwd
[Email protected] ~]#

The Uniq command, which is used to delete duplicate rows.

-C statistics Number of rows to repeat

[Email protected] ~]# VI 0.txt

Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Ioperator:x:11:0:operator:/root:/sbin/nologin
21213
123213
222

222

222
[Email protected] ~]#
[[email protected] ~]# uniq 0.txt 222 Repeat, it's been deleted.
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Ioperator:x:11:0:operator:/root:/sbin/nologin
21213
123213
222

[Email protected] ~]#

[Email protected] ~]# sort 0.txt |uniq-c
1
1 123213
1 21213
3 222
1 Adm:x:3:4:adm:/var/adm:/sbin/nologin
1 Bin:x:1:1:bin:/bin:/sbin/nologin
1 Daemon:x:2:2:daemon:/sbin:/sbin/nologin
1 Halt:x:7:0:halt:/sbin:/sbin/halt
1 Ioperator:x:11:0:operator:/root:/sbin/nologin
1 Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
1 Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
1 Root:x:0:0:root:/root:/bin/bash
1 Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
1 Sync:x:5:0:sync:/sbin:/bin/sync
[Email protected] ~]#

Three, tee, TR, split command

Tee is followed by a file name, acting like a redirect, but it is directed more than one function, that is, the file is written to the following file, will also do the display.

[[email protected] ~]# sort 0.txt |uniq-c |tee 2.txt   REDIRECT the front to 2.txt and display it
1
1 123213
1 21213
3 222
1 adm:x:3:4:adm:/var/adm:/sbin/ Nologin
1 bin:x:1:1:bin:/bin:/sbin/nologin
1 daemon:x:2:2:daemon:/sbin:/sbin/nologin
1 halt:x:7:0:halt:/ Sbin:/sbin/halt
1 ioperator:x:11:0:operator:/root:/sbin/nologin
1 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
1 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
1 root:x:0:0:root:/root:/bin/bash
1 shutdown:x:6:0: Shutdown:/sbin:/sbin/shutdown
1 Sync:x:5:0:sync:/sbin:/bin/sync

[Email protected] ~]# cat 2.txt
1
1 123213
1 21213
3 222
1 Adm:x:3:4:adm:/var/adm:/sbin/nologin
1 Bin:x:1:1:bin:/bin:/sbin/nologin
1 Daemon:x:2:2:daemon:/sbin:/sbin/nologin
1 Halt:x:7:0:halt:/sbin:/sbin/halt
1 Ioperator:x:11:0:operator:/root:/sbin/nologin
1 Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
1 Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
1 Root:x:0:0:root:/root:/bin/bash
1 Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
1 Sync:x:5:0:sync:/sbin:/bin/sync
[Email protected] ~]#

The TR command, used to replace characters, is commonly used to handle special symbols appearing in the document,

-D Delete a character, followed by the deleted character

-S Delete duplicate characters

[[email protected] ~]# echo "davery" |tr ' [d] ' [d] ' just follow d for D
Davery
[Email protected] ~]#

[[email protected] ~]# echo "Davery" |tr ' d ' d ' only follow d for D
Davery
[Email protected] ~]#

[[email protected] ~]# echo "davery" |tr ' [A-z] ' [A-z] ' all capitalization
Davery
[Email protected] ~]#

[Email protected] ~]# echo "davery" |tr ' [A-z] ' [1] '
]1] []]
[[email protected] ~]# echo "davery" |tr ' [A-z] ' 1 ' into the number 1
111111
[Email protected] ~]#

Split command

For cutting files

-B indicates that the document is delimited by size, with the default unit of byte and M K

-L separates documents according to number of rows

[[email protected] ~]# find/etc/-type f-name "*conf"-exec Cat {} >> 0.txt \;
[[email protected] ~]# ls
0.tx~ 0.txt.gz 1.txt 3.txt 5036 anaconda-ks.cfg.01 a.txt davery~ uear1
0.txt 0_txt.swp 2.txt 4913 5159 anaconda-ks.cfg.1 davery make User1
[Email protected] ~]#

[Email protected] ~]# Du-sh 0.txt
212K0.txt
[Email protected] ~]#

0.tx~ 0.txt.gz 1.txt 3.txt 5036 anaconda-ks.cfg.01 a.txt davery~ Test user1
0.txt 0_txt.swp 2.txt 4913 5159 anaconda-ks.cfg.1 davery make Uear1
[Email protected] ~]#split-b 0.txt
[[email protected] ~]# ls
0.tx~ a.txt xaf xar xbd xbp xcb xcn xcz xdl xdx xej xev xfh xft xgf xgr xhd xhp xib
0.txt davery xag xas xbe xbq xcc xco xda xdm xdy xek xew xfi xfu xgg xgs xhe XHQ xic
0.txt.gz davery~ xah xat xbf xbr xcd xcp xdb xdn xdz xel xex xfj xfv xgh xgt xhf xhr XID
0_TXT.SWP make Xai xau xbg xbs xce xcq xdc xdo xea xem xey xfk xfw xgi xgu xhg xhs Xie
1.txt test Xaj Xav xbh xbt xcf xcr xdd xdp xeb xen xez xfl xfx xgj xgv xhh xht xif
2.txt uear1 Xak xaw xbi xbu xcg xcs xde xdq xec xeo xfa xfm xfy xgk xgw xhi xhu Xig
3.txt user1 xal xax xbj xbv xch xct xdf xdr xed xep xfb xfn xfz xgl xgx xhj XHV xih
4913 xaa xam xay xbk xbw xci xcu xdg xds xee xeq xfc xfo XGA xgm xgy xhk XHW XII
5036 xab Xan Xaz xbl xbx xcj xcv xdh xdt xef xer xfd xfp xgb xgn xgz xhl xhx Xij
5159 xac xao xba xbm xby xck xcw xdi xdu xeg xes xfe xfq xgc xgo xha xhm xhy
anaconda-ks.cfg.01 xad xap xbb xbn xbz xcl xcx xdj xdv xeh xet xff xfr xgd xgp XHB xhn xhz
Anaconda-ks.cfg.1 xae xaq xbc xbo xca xcm xcy XDK xdw xei xeu xfg xfs xge xgq xhc Xho Xia
[Email protected] ~]#

Split-b 0.txt ABC designation name

Four, Shell special symbols

$ variable before the identifier, combined! To use

[[email protected] ~]# ls 0.txt
0.txt
[Email protected] ~]#!$
0.txt

If you want to execute multiple commands on one line, use;

[Email protected] ~]# mkdir test1; Touch 0.1txt; Touch 0.2txt; Touch 0.3txt

~ Indicates the user's home directory, root user's home directory/root, ordinary user/home/username

[Email protected] ~]# CD ~
[Email protected] ~]# pwd
/root
[email protected] ~]# su davery
[Email protected] root]$ CD ~
[Email protected] ~]$ pwd
/home/davery
[Email protected] ~]$

& Put the command in the background to perform the need to add &

[Email protected]/]# sleep &
[1] 2606
[[email protected]/]# jobs
[1]+ Run in Sleep &
[Email protected]/]#

REDIRECT Symbol

> Substitution, >> append, 2> error redirection, 2>> error redirection append

[] represents any one of the character combinations [0-9],[a-z A-Z],[ABC]

&& | |

[[email protected]/]# ls 0.txt | | Wc-l 2.txt represents or, two commands one can perform an achievement row

[[email protected]/]# ls 0.txt && wc-l 2.txt Front Command successful execution of the command behind

Linux Centos7 Shell Special symbols, cut commands, Sort_wc_uniq commands, tee_tr_split commands, shell special symbols

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.