wc:
单词统计
grep “root” /etc/passwd | wc
2 2 77
第一个数指的是行数,第二个指的是单词,第三个指的是字节数
因为没有空格就会把一块看出一个字节
-w是只显示单词数
-l是只显示行数
-c是字节数
-L是最大长度的行的字节
cut:
剪切工具
-d CHAR:以指定的字符为分隔符
-f files :挑选出的字段
#:指定的单个字段
#-#:连续的多个字段
#,#:离散的多个字段
显示用户名和uid
[root@localhost ~]# cut -d: -f1,3 /etc/passwd
sort:
排序命令
按uid大小排序
[root@localhost ~]# cut -d: -f1,3 /etc/passwd | sort -n -t: -k2
root:0
daemon:2
adm:3
lp:4
sync:5
-n :基于数值大小而非字符进行排序
-k: 指定排序的字段
-t:指定分隔符
-r:逆序排序
-f:忽略字符大小写
-u:重复的行保留一份
统计每一种shell各有多少人用?
[root@localhost ~]# cut -d: -f7 /etc/passwd | uniq -c
1 /bin/bash
3 /sbin/nologin
1 /bin/sync
1 /sbin/shutdown
1 /sbin/halt
10 /sbin/nologin
2 /bin/bash
1 /bin/tsh
4 /bin/bash
1 /sbin/nologin
2 /bin/bash
1 /sbin/nologin
2 /bin/bash
1 /sbin/nologin
8 /bin/bash
[root@localhost ~]# cut -d: -f7 /etc/passwd | sort | uniq -c
19 /bin/bash
1 /bin/sync
1 /bin/tsh
1 /sbin/halt
16 /sbin/nologin
1 /sbin/shutdown
统计之前要使用 sort来排序,uniq只是说下一行一样的才算一样,下多行一样的不算
报告或者移除重复的行
uniq [OPTION]… [INPUT [OUTPUT]]
-c 显示每行的重复次数
-u 仅显示未曾重复过的行
-d 仅显示重复过的行
diff:compare files line by line 逐行比较稳健的内容
diff [OPTION]… FILES
diff /path/to/oldfile /path/to/newfile > /path/to/patch_file –生成补丁
-u:显示要修改行的上下文 ,默认显示3行
patch:向文件打补丁
patch [options] -i /path/to/patch_file /path/to/oldfile
patch -i fstab.patch fstab
patch /path/to/oldfile < /path/to/patch_file