[命令] Linux 命令 uniq (文件里字符重复的管理)

案例一:uniq 命令去重

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq
a1
b2
c3
d2
e3

(补充:这里以给 test.txt 文件里的字符为例)

案例二:uniq 只显示重复的行

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -d
a1
c3

(补充:这里以只显示 test.txt 文件里重复的行为例)

案例三:uniq 只显示不重复的行

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -u
b2
d2
e3

(补充:这里以只显示 test.txt 文件里不重复的行为例)

案例四:显示每个字符出现的次数

# cat test.txt 
a1
b2
c3
a1
d2
e3
a1
c3

# sort test.txt  | uniq -c
      3 a1
      1 b2
      2 c3
      1 d2
      1 e3

(补充:这里以显示 test.txt 每个字符出现的次数为例)

[内容] Linux 进程修正值 (nice 值) 的设置

内容一:进程优先级和修正值(nice 值)的关系

1.1 进程优先级的作用

进程的真正优先级越小,则此进程则越能优先被执行

1.2 进程优先级和修正值(nice 值)的关系

进程的真正优先级 = 进程默认优先级 + 修正值(nice 值)

1.3 修正值(nice 值)的范围

从 -20 到 +19

内容二:修正值(nice 值)的设置

2.1 设置修正值(nice 值)的格式

# nice -n <correction value> <command>

或者:

# nice --adjustment=<correction value> <command>

或者:

# nice -<correction value> <command>

2.2 设置修正值(nice 值)的案例

# nice -n 10 top

或者:

# nice --adjustment=10 top

或者:

# nice -10 top

(注意:这里的 -10 不是指负数 10 而是指正数 10)

(补充:这里以修正值为 10 启动 top 命令为例)

内容三:显示进程的修正值

# top

或者:

# ps -ef


补充:
1) PRI 代表进程默认的优先级
2) NI 代表进程的修正值(nice 值)
3) 进程的真正优先级 = PRI + NI
4) 如果多个进程的真正优先级一样,则 root 用户的进程被优先执行

[命令] Linux 命令 sort(对数字或字母进行排序)

内容一:sort 命令的选项

1) -b 排序时忽略每行前面的空格
2) -c 检查是否已排序
3) -f 排序时忽略大小写字母
4) -n 按照数值到大小进行排序
5) -o 将排序结果导入到指定文件
6) -r 以相反的顺序进行排序
7) -t 指定排序的分隔符
8) -k 以指定的列进行排序

内容二:sort 命令的案例

2.1 案例一:检查是否已经排序

# cat test.txt
3
5
4
2
1

# sort -c test.txt 
sort: test.txt:3: disorder: 4

(补充:这里以检查 test.txt 文件里的排列为例)

2.2 案例二:sort 排序一列数字

# cat test.txt
3
5
4
2
20
1

# sort -n test.txt 
1
2
3
4
5
20

(补充:这里以排列 test.txt 文件里的列为例)

2.3 案例三:sort 排序一列字母

# cat test.txt 
c
e
d
b
a

# sort test.txt 
a
b
c
d
e

(补充:这里以排列 test.txt 文件里的列为例)

2.4 案例四:sort 以相反的顺序进行排序

# cat test.txt 
c
e
d
b
a

# sort -r test.txt 
e
d
c
b
a

(补充:这里以排列 test.txt 文件里的列为例)

2.5 案例五:sort 以 2 列中的第 1 列进行排序

# cat test.txt 
3 d
5 c
4 a
2 e
1 b

# sort test.txt 
1 b
2 e
3 d
4 a
5 c

(补充:这里以排列 test.txt 文件里的列为例)

2.6 案例六:sort 以 2 列中的第 2 列进行排序

# cat test.txt 
3 d
5 c
4 a
2 e
1 b

# sort -k2 test.txt 
4 a
1 b
5 c
3 d
2 e

(补充:这里以排列 test.txt 文件里的列为例)

2.7 案例七:sort 对 IP 地址进行排序

# cat test.txt 
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1

# sort test.txt
10.0.200.1
10.0.200.10
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10

(补充:这里以排列 test.txt 文件里的列为例)

2.8 案例八:sort 以 IP 地址的第三组数字进行排序

# cat test.txt 
10.0.200.10
172.16.50.10
192.168.100.1
192.168.100.10
172.16.50.1
10.0.200.1

# sort -t'.' -k3n test.txt
172.16.50.1
172.16.50.10
192.168.100.1
192.168.100.10
10.0.200.1
10.0.200.10

(补充:这里以排列 test.txt 文件里的列为例)