一、wc
用来统计
主要 -l 使用
eg1: 查看rpm包个数
[root@localhost day2]# rpm -qa | wc -l
346
eg2:查看行数
[root@localhost day2]# cat ceshi
a
b
c
d
[root@localhost day2]# wc -l < ceshi
4
二、*sort
主要用来排序
[root@localhost day2]# cat test1
111
10
22
34
3433
998
按从小到大排序
[root@localhost day2]# sort -n test1
10
22
34
111
998
3433
按从大到小排序
[root@localhost day2]# sort -rn test1
3433
998
111
34
22
10
可以将/etc/passwd 中内容按照uid排序
[root@localhost day2]# sort -t : -k 3 -n /etc/passwd
三、cut
主要用来切割
可以cut --help查看帮助
[root@localhost day2]# cut -d : -f1,3,5
/etc/passwd
[root@localhost day2]# echo "this is a cat" | cut -c 6-10
is a
[root@localhost day2]# cat ceshi | cut -c 6-10
is a
[root@localhost day2]# cat ceshi
this is a cat
b
c
d
四、 uniq
用于统计
[root@localhost day2]# cat test2
cat
pig
dog
bird
book
cat
pig
cat
按照出现频率进行排序(这里例举从高到低频率)
[root@localhost day2]# sort test2 | uniq -c | sort -rn
2 pig
2 cat
1 dog
1 cat
1 book
1 bird
#sort test2是将test2中单词按照字母顺序排序,接着管道传到uniq -c是给出不同单词出现的频率,最后sort -rn 是将sort test2 | uniq -c的内容按照频率排出。
按照被访问频率从高到底排序,只输出ip
[root@localhost httpd]# cut -d " " -f1 /var/log/httpd/access_log | sort | uniq -c | sort -rn
9 192.168.157.131
3 192.168.157.136
其中cut -d " " -f1 /var/log/httpd/access_log是将如图内容中的ip分割出来,接着传给sort将ip按照大小排序,然后再传给uniq -c是给出访问频率,最后sort -rn 将频率从高到低排出
五、tr
可以替换或者删除
[root@localhost day2]# echo "hello SHell" | tr "A-Z" "a-z"
hello shell
[root@localhost ~]# echo "my name is xiaoming" | tr "m" "n"
ny nane is xiaoning