shell special symbols, cut,sort,wc,uniq,tee,tr,split commands

shell special symbols (1)

  • Special symbols
    • * Any arbitrary character
    • ? Any character
    • * # comment character
    • *\ Definition character
    • * pipe symbol

cut command

Cut is used to intercept a field in the form of # cut d `separator character'[-cf]n, n being a number.

Options:

  • d is followed by a separator, which should be enclosed in single quotation marks.
  • c is followed by the number of characters.
  • f is followed by a number of blocks.
[root@yolks1 ~]# cat /etc/passwd |head -2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@yolks1 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1
root
bin
[root@yolks1 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,3
root:0
bin:1
[root@yolks1 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1-4
root:x:0:0
bin:x:1:1
[root@yolks1 ~]# cat /etc/passwd |head -2 |cut -c 1
r
b

sort_wc_uniq command

sort command

Sort is used for sorting in the form of sort[-t separator] [-kn1,n2] [-nru], where n1 and N2 refer to numbers.

Options:

  • n denotes the use of pure numeric sorting (numeric zero for processing)
  • r denotes reverse ordering
  • u denotes de-duplication
  • t is followed by character splitting, which works the same way as cut's-d option
  • kn1,n2 means sorting from n1 interval to n2 interval. It can only write - kn1, that is, sorting n1 field.
#Copy the / etc/passwd file to the first 10 lines to the 1.txt file and do the following
[root@yolks1 ~]# sort !$
sort 1.txt
<
>
[
{
****&&&&&
%##@@@
222111
222334
%%%3333
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
eerttr454
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
shshjs
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
wwwwww
[root@yolks1 ~]# sort -n 1.txt
<
>
[
{
****&&&&&
%##@@@
%%%3333
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
eerttr454
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
shshjs
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sync:x:5:0:sync:/sbin:/bin/sync
wwwwww
222111
222334
[root@yolks1 ~]# sort -r 1.txt
wwwwww
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
shshjs
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
eerttr454
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
%%%3333
222334
222111
%##@@@
****&&&&&
{
[
>
<

wc command

Commands are used to count the number of lines, characters, or words in a document.

option

  • l (Statistical rows)
  • M (Statistical Character Number)
  • w (Number of Statistical Words)
[root@yolks1 ~]# cat !$
cat 5.txt
abc
123 1122
22,aa
bb,cc
[root@yolks1 ~]# wc -l !$
wc -l 5.txt
4 5.txt #Output is 4 lines
[root@yolks1 ~]# wc -m 5.txt
25 5.txt
[root@yolks1 ~]# wc -w 5.txt
5 5.txt

uniq command

Deduplication

Options:

  • c Statistical Repetition Number
[root@yolks1 ~]# !cat
cat 5.txt
abc
123 1122
22,aa
bb,cc
bb,cc
bb,cc
[root@yolks1 ~]# !uniq
uniq 5.txt
abc
123 1122
22,aa
bb,cc
[root@yolks1 ~]# uniq -c 5.txt
      1 abc
      1 123 1122
      1 22,aa
      3 bb,cc
[root@yolks1 ~]# sort 5.txt |uniq
123 1122
22,aa
abc
bb,cc

tee_tr_split command

tee

tee is followed by the file name, which is similar to redirection > and has one more function than redirection. It writes the file to the following file and displays it on the screen. It is usually used after the pipeline character |.

option

  • a Additional Meaning
[root@yolks1 ~]# sort 2.txt |uniq -c |tee 5.txt
      1 adm:x:3:4:adm:/var/adm:/sbin/nologin
      1 bin:x:1:1:bin:/bin:/sbin/nologin
      1 chrony:x:998:996::/var/lib/chrony:/sbin/nologin
      1 daemon:x:2:2:daemon:/sbin:/sbin/nologin
      1 dbus:x:81:81:System message bus:/:/sbin/nologin
      1 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
      1 games:x:12:100:games:/usr/games:/sbin/nologin
      1 halt:x:7:0:halt:/sbin:/sbin/halt
      1 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
      1 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
      1 nobody:x:99:99:Nobody:/:/sbin/nologin
      1 operator:x:11:0:operator:/root:/sbin/nologin
      1 polkitd:x:999:997:User for polkitd:/:/sbin/nologin
      1 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
      1 root:x:0:0:root:/root:/bin/bash
      1 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
      1 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
      1 sync:x:5:0:sync:/sbin:/bin/sync
      1 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
[root@yolks1 ~]# cat 5.txt
      1 adm:x:3:4:adm:/var/adm:/sbin/nologin
      1 bin:x:1:1:bin:/bin:/sbin/nologin
      1 chrony:x:998:996::/var/lib/chrony:/sbin/nologin
      1 daemon:x:2:2:daemon:/sbin:/sbin/nologin
      1 dbus:x:81:81:System message bus:/:/sbin/nologin
      1 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
      1 games:x:12:100:games:/usr/games:/sbin/nologin
      1 halt:x:7:0:halt:/sbin:/sbin/halt
      1 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
      1 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
      1 nobody:x:99:99:Nobody:/:/sbin/nologin
      1 operator:x:11:0:operator:/root:/sbin/nologin
      1 polkitd:x:999:997:User for polkitd:/:/sbin/nologin
      1 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
      1 root:x:0:0:root:/root:/bin/bash
      1 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
      1 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
      1 sync:x:5:0:sync:/sbin:/bin/sync
      1 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin

tr command

Used to replace characters

[root@yolks1 ~]# echo "hello,yolks" |tr '[hy]' '[HY]'
Hello,Yolks
[root@yolks1 ~]# echo "hello,yolks" |tr '[a-z]' '[A-Z]'
HELLO,YOLKS

split command

split is used to cut documents. split -[b][l] file [specify the name after cutting]

Options:

  • b denotes that documents are segmented by size in byte
  • l Represents dividing documents according to the number of rows
[root@yolks1 ~]# du -sh 5.txt
52K	5.txt
root@yolks1 ~]# split -b 20k 5.txt
[root@yolks1 ~]# ls -lh xa*
-rw-r--r-- 1 root root 20K 7 Month 123:47 xaa
-rw-r--r-- 1 root root 20K 7 Month 123:47 xab
-rw-r--r-- 1 root root 12K 7 Month 123:47 xac
[root@yolks1 ~]# wc -l 5.txt
1080 5.txt
[root@yolks1 ~]# split -l 500 5.txt
[root@yolks1 ~]# ls -hl xa*
-rw-r--r-- 1 root root  24K 7 Month 123:54 xaa
-rw-r--r-- 1 root root  24K 7 Month 123:54 xab
-rw-r--r-- 1 root root 3.9K 7 Month 123:54 xac

shell special symbols (2)

  • Variable prefix,!$combination, which means end of line
  • Multiple commands are written on one line, separated by semicolons
  • 65
  • Place the command behind it and leave it behind the scenes.
  • > >> 2> 2>> &>
  • [] One of the specified strings, [0-9],[a-zA-Z][abc]
  • | | and &&, between commands
[root@yolks1 ~]# ls
1.txt  2.txt  4.txt  anaconda-ks.cfg.1  test_windoiws_upload_file.txt  xab
234    3.txt  5.txt  stick_bit          xaa                            xac
[root@yolks1 ~]# rm -rf xa* ;ls #Multiple commands use';'Separate them.
1.txt  2.txt  4.txt  anaconda-ks.cfg.1  test_windoiws_upload_file.txt
234    3.txt  5.txt  stick_bit
#Or, if the current command is executed correctly, the subsequent command will not be executed; if the first fails, the second will be executed.
[root@yolks1 ~]# cat 1.txt || wc -l 4.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
operator:x:11:0:operator:/root:/sbin/nologin
shshjs
222334
wwwwww
eerttr454
222111
%%%3333
%##@@@
****&&&&&
<
>
{
[
#And the relationship between the success of the previous execution will be followed by the implementation of the latter
[root@yolks1 ~]# cat 1.txt && wc -l 4.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
operator:x:11:0:operator:/root:/sbin/nologin
shshjs
222334
wwwwww
eerttr454
222111
%%%3333
%##@@@
****&&&&&
<
>
{
[
1 4.txt

Tags: ftp network shell DBus

Posted on Tue, 25 Dec 2018 10:03:06 -0800 by jrtaylor