linux cut, sort_wc_uniq, tee_tr_split commands and some special symbols

Keywords: ftp shell vim Anaconda

The shell special symbol cut command:


1. * Any arbitrary character (this is a wildcard character)

2. Any character

3. # Annotation Character

4. \ Definition character

5,| Pipeline Character


Several pipeline-related orders:


1. cut partition, - d separator - f specifies the segment number - c specifies the number of characters.

Example:

[root@aminglinux-01 ~]# cat /etc/passwd |head
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
[root@aminglinux-01 ~]# cat /etc/passwd |head -2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@aminglinux-01 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1
root
bin
[root@aminglinux-01 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2
root:x
bin:x
[root@aminglinux-01 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1-3
root:x:0
bin:x:1
[root@aminglinux-01 ~]# cat /etc/passwd |head -2 |cut -c 4
t
:


The sort_wc_uniq command:


2. sort sort sort, - n in numeric order - r reverse order - t separator - kn1/-kn1,n2

Examples are as follows:

root@aminglinux-01 ~]# Sort/etc/passwd (sort by ID number, number, letter, etc.)
adm:x:3:4:adm:/var/adm:/sbin/nologin
aminglinux:x:1002:1002::/home/aminglinux:/bin/bash
aming:x:1000:1005::/home/aming:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
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

3. wc-l Statistical Row Number-m Statistical Character Number-w Statistical Word

Example:

[root@aminglinux-01 ~]# wc -l 1.txt
22 1.txt
[root@aminglinux-01 ~]# wc -m 1.txt
450 1.txt
[root@aminglinux-01 ~]# wc -m 2.txt
0 2.txt
[root@aminglinux-01 ~]# wc -w 2.txt
0 2.txt

4. uniq de-weighting, -c statistical rows

uniq commands are used separately to de-duplicate, but only in the same sequence of lists.

[root@aminglinux-01 ~]# vim 2.txt
[root@aminglinux-01 ~]# cat 2.txt
123
abc 111,222
123
abc
1
2
1
[root@aminglinux-01 ~]# uniq 2.txt// No sequence is identical and cannot be de-duplicated.
123
abc 111,222
123
abc
1
2
1
[root@aminglinux-01 ~]# vim 2.txt // Change the number sequence
[root@aminglinux-01 ~]# cat 2.txt
123
abc 111,222
123
abc
1
1
2
[root@aminglinux-01 ~]# uniq 2.txt // Reduplicate the same number
123
abc 111,222
123
abc
1
2

Combining with the sort command, use sorting first, then de-duplicate, calculate the number of repetitions, example:

[root@aminglinux-01 ~]# sort 2.txt // Automatic sort 2.txt Text List
1
1
123
123
2
abc
abc 111,222
[root@aminglinux-01 ~]# sort 2.txt |uniq // / de-weighting
1
123
2
abc
abc 111,222
[root@aminglinux-01 ~]# Sort 2.txt | uniq-c // / Calculate the number of iterations
2 1
2 123
1 2
1 abc
1 abc 111,222


The tee_tr_split command:


5, tee and > Similar, redirection is also displayed on the screen

Example:

[root@aminglinux-01 ~]# cat a.txt
[root@aminglinux-01 ~]# sort 2.txt |uniq -c |tee a.txt
2 1
2 123
1 2
1 abc
1 abc 111,222
[root@aminglinux-01 ~]# cat a.txt
2 1
2 123
1 2
1 abc
1 abc 111,222
[root@aminglinux-01 ~]# Sort 2.txt | uniq - C | Tee - a. TXT // tee plus - a is an addition
2 1
2 123
1 2
1 abc
1 abc 111,222
[root@aminglinux-01 ~]# cat a.txt
2 1
2 123
1 2
1 abc
1 abc 111,222
2 1
2 123
1 2
1 abc
1 abc 111,222

6. tr replaces characters, tr'a''b', case replaces tr' [a-z]''[A-Z]'

Example:

[root@aminglinux-01 ~]# echo "aminglinux" |tr '[al]' '[AL]'
AmingLinux
[root@aminglinux-01 ~]# echo "aminglinux" |tr '[a-z]' '[A-Z]'
AMINGLINUX
[root@aminglinux-01 ~]# echo "aminglinux" |tr '[a-z]' '1'
1111111111

7. split cutting, - b size (default unit byte), - l line number (cut log, two usages)

Use commands:

split -b 1000m bigfile
split -l   1000    bigfile

Example:

[root@aminglinux-01 test]# ls
a.txt
[root@aminglinux-01 test]# split -b 100k a.txt
[root@aminglinux-01 test]# ls
a.txt  xaa  xab  xac
[root@aminglinux-01 test]# du -sh *
256K	a.txt
100K	xaa
100K	xab
52K	xac
[root@aminglinux-01 test]# rm -f x*
[root@aminglinux-01 test]# split -b 100k a.txt abc
[root@aminglinux-01 test]# ls
abcaa  abcab  abcac  a.txt
[root@aminglinux-01 test]# split -b 100k a.txt abc.
[root@aminglinux-01 test]# ls
abcaa  abc.aa  abcab  abc.ab  abcac  abc.ac  a.txt
[root@aminglinux-01 test]# rm -f abc*
[root@aminglinux-01 test]# split -l 1000 a.txt
[root@aminglinux-01 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
[root@aminglinux-01 test]# wc -l *
6495 a.txt
1000 xaa
1000 xab
1000 xac
1000 xad
1000 xae
1000 xaf
495 xag
12990 Total consumption


Under shell special symbols:


1, $variable prefix,!$combination, which means the end of the line

2. Multiple commands are written on one line, separated by semicolons

[root@aminglinux-01 ~]# ls 1.txt ; wc -l 2.txt
1.txt
7 2.txt

3. ~User's home directory, followed by regular expressions to represent matchers

4. & After the command, the command will be dropped behind the scenes.

5,> >> 2> 2>> &>


>: Correct redirection will overwrite the previous files.

Additional orientation and correct output of additional content.

2>: Error redirection

2>: Additional error redirection

&>: Represents correct and error output redirection


6. [] One of the specified characters, such as [0-9],[a-zA-Z],[abc]

7, | | and &&, used between commands.

Manifest or mean that when two commands are executed simultaneously, if the first command is not executed successfully, then the second command is executed. If the first command is executed successfully, then the second command is not executed. Examples are as follows:

[root@aminglinux-01 ~]# ls 1a.txt || wc -l 2.txt
ls: Unable to access 1 a.txt: No file or directory
7 2.txt
[root@aminglinux-01 ~]# ls 1.txt || wc -l 2.txt
1.txt

&&: When two commands are executed at the same time, if the previous command is executed successfully, the latter command will not be executed.

Examples are as follows:

[root@aminglinux-01 ~]# ls 1.txt && wc -l 2.txt
1.txt
7 2.txt
[root@aminglinux-01 ~]# ls 1a.txt && wc -l 2.txt
ls: Unable to access 1 a.txt: No file or directory


Experiment:

[root@aminglinux-01 ~]# ls
111  1_heard.txt.bak  1.txt      234    3.txt  aa.txt  anaconda-ks.cfg  test
123  1_sorft.txt.bak  1.txt.bak  2.txt  456    aming2  bb.txt           Introduction to Anno Yunzhi Platform PPT Template).pptx
[root@aminglinux-01 ~]# [ -d aminglinux ] || mkdir aminglinux
[root@aminglinux-01 ~]# ls
111  1_heard.txt.bak  1.txt      234    3.txt  aa.txt  aminglinux       bb.txt  Introduction to Anno Yunzhi Platform PPT Template).pptx
123  1_sorft.txt.bak  1.txt.bak  2.txt  456    aming2  anaconda-ks.cfg  test
[root@aminglinux-01 ~]# [ -d aminglinux ] && mkdir aminglinux
mkdir: Unable to create directory"aminglinux": file already exist
[root@aminglinux-01 ~]# [ -d aminglinux ] || mkdir aminglinux

Interpretation:

[-d aminglinux]: Determines whether a directory exists.


Posted by cesar110 on Mon, 24 Dec 2018 10:57:06 -0800