cut 命令
cut命令可以按指定的分隔符分割成多列
--命令参数
-d 切割字符
-f 列的第几个参数
-c 以字符为单位进行分割
-c1-10 指定字符串范围行的第一个到第十个
--按字段筛选,输出第一列和第二列
[root@linux /]# cat test
123 456 aaa:789
654 321 bbb:000
abc def ccc:ghi
--截取每一行的第一个区域的内容
[root@linux /]# cut -d " " -f1 test
123
654
abc
--截取每一行的第一第二区域的内容
[root@linux /]# cut -d " " -f1,2 test
123 456
654 321
abc def
--以字符为单位进行分割, 从第五个到结尾
[root@linux /]# cut -c 5- test
456 aaa:789
321 bbb:000
def ccc:ghi
sort命令
--语法格式
sort [参数] [文件]
--sort命令常用参数
-n 按字符串数值排序,与-g区别为不转为浮点数
-g 按通用数值排序,支持科学计数法
-f 忽略大小写,默认大小写字母不同
-k 排序从POS1开始,若指定POS2,则POS2结束,否则以pos1排序
-t 指定列的分割符
-r 降序排序,默认为升序
-h 使用易读性数字(例如: 2K 1G)
-u 去除重复的行
-o 将输出写入文件
默认排序
--默认情况下,sort命令,以字母序进行文本排序,如下
[root@linux /]# cat test
123 456 aaa:789
123 456 aaa:789
654 321 bbb:000
dvf ebq evs:sfb
abc def ccc:ghi
[root@linux /]# sort test
123 456 aaa:789
123 456 aaa:789
654 321 bbb:000
abc def ccc:ghi
dvf ebq evs:sfb
数字排序
--如果想对数字进行排序,可以使用-n参数
[root@linux /]# cat test
123 456 aaa:789
654 321 bbb:000
123 456 aaa:789
dvf ebq evs:sfb
abc def ccc:ghi
[root@linux /]# sort test -n
abc def ccc:ghi
dvf ebq evs:sfb
123 456 aaa:789
123 456 aaa:789
654 321 bbb:000
文件夹大小排序
[root@linux xxx]# du -h
420K ./cobaltstrike/third-party
24K ./cobaltstrike/data
264K ./cobaltstrike/logs/200807/172.16.0.1/screenshots
280K ./cobaltstrike/logs/200807/172.16.0.1
292K ./cobaltstrike/logs/200807
296K ./cobaltstrike/logs
24M ./cobaltstrike
24M .
[root@linux xxx]# du -h ./ |sort -hr
24M ./cobaltstrike
24M ./
420K ./cobaltstrike/third-party
296K ./cobaltstrike/logs
292K ./cobaltstrike/logs/200807
280K ./cobaltstrike/logs/200807/172.16.0.1
264K ./cobaltstrike/logs/200807/172.16.0.1/screenshots
24K ./cobaltstrike/data
--对文件内容进行去重
--如果文件内容有很多重复的,需要进行去重。sort也是支持的,可以通过-u参数使用
[root@linux /]# cat test
123 456 aaa:789
654 321 bbb:000
123 456 aaa:789
dvf ebq evs:sfb
abc def ccc:ghi
[root@linux /]# sort test -u
123 456 aaa:789
654 321 bbb:000
abc def ccc:ghi
dvf ebq evs:sfb
wc 命令
--语法格式
wc [参数] [文件]
常用参数
-w 统计字数
-c 统计字节数
-l 统计行数
-m 统计字符数
-L 打印最长行的长度
--统计行数
[root@linux /]# cat test|wc -l
5
--统计单词数
[root@linux /]# cat test|wc -w
15
--统计字符数
[root@linux /]# cat test|wc -m
80
uniq 命令
--语法格式
uniq [参数] [文件]
--常用参数
-c 打印每行在文本中重复出现的次数
-d 只显示有重复的纪录,每个重复纪录只出现一次
-u 只显示没有重复的纪录
[root@linux /]# cat test
hello
hello
world
end
--打印每行在文本中重复出现的次数
[root@linux /]# uniq -c /test
2 hello
1 world
1 end
--只显示没有重复的纪录
[root@linux /]# uniq -u /test
world
end
tr 命令
--语法格式
tr [参数] [字符串1] [字符串2]
--常用参数
-c 选定字符串1中字符集的补集,即反选字符串1的补集
-d 删除字符串1中出现的所有字符
-s 删除所有重复出现的字符序列,只保留一个
--将大写字母转换成小字母
[root@linux /]# echo "hello"|tr "[a-z]" "[A-Z]"
HELLO
[root@linux /]# echo "hello"|tr 'he' 'HE'
HEllo
--删除数字
[root@linux /]# echo "hello 22233"|tr -d "[0-9]"
hello
--删除重复字符
[root@linux /]# echo "122333"|tr -s "23"
123