1 cut
从文件的每一行截取一部分内容
-d
:delimiter,指定分割符-f
:field,取出指定字段数内容c
:character,取出指定字符位置的内容-c7-
:取出第七位到行尾的内容-c7-10
:取出第七到第十位的内容-c-7
:取出行首到第七位的内容
2 sort
排序
-t
:指定分割符-k
:指定字段数-r
:采用逆序排序-n
:以数字大小进行排序-u
:unique,去重
3 uniq
直接去重,要以“正常的人认为的去重”要先做排序
-c
:counting,统计重复次数
4 wc
word counting,单词、字符数、字节数、行数统计
-l
:line,行数-w
:word,单词-m
:字符数-c
:字节数
5 tee
将上一个命令的输出结果重定向到文件并作标准输出
COMMAND … | tee FILE
:相当于COMMAND … > FILE
再+一个输出-a
:append,追加
6 xargs
将上一个命令的输出每一行作为参数传递给xargs
后面的命令
-d
:指定分割符-n
:指定一次传递n个参数-I+STR
:指定使用符号替代需要传递的参数-t
:显示执行命令
[root@localhost ~]# echo -n '/etc/fstab:/etc/inittab' | xargs -t -d: -n1 -I{} cp -a {} /tmp
cp -a /etc/fstab /tmp
cp -a /etc/inittab /tmp
[root@localhost ~]# find . -size -1k -print0 | xargs -0 ls -l
-rw-r--r--. 1 root root 0 3月 20 04:44 ./a
-rw-r--r--. 1 root root 0 3月 20 04:40 ./b
-rw-r--r--. 1 root root 0 2月 6 09:55 ./.cache/abrt/applet_dirlist
-rw-r--r--. 1 root root 0 2月 6 09:55 ./.cache/gnome-shell/update-check-3.28
-rw-r--r--. 1 root root 0 2月 6 09:55 ./.local/share/flatpak/.changed
-rw-r--r--. 1 root root 0 2月 6 09:55 ./.local/share/gnome-settings-daemon/input-sources-converted
-rw-r-----. 1 root root 0 2月 6 09:55 ./.local/share/tracker/data/.meta.isrunning
7 join
合并文件内容
# month1
1 一月
2 二月
3 三月
4 四月
5 五月
6 六月
7 七月
8 八月
9 九月
10 十月
11 十一月
12 十二月
13 十三月
# month2
1 January
2 February
3 March
4 April
5 May
6 June
7 July
8 August
9 September
10 October
11 November
12 December
14 MonthUnknown
join month1 month2
:相当于数据库的内连接,关键字不匹配的行不会输出
[root@localhost ~]# join month1 month2
1 一月 January
2 二月 February
3 三月 March
4 四月 April
5 五月 May
6 六月 June
7 七月 July
8 八月 August
9 九月 September
10 十月 October
11 十一月 November
12 十二月 December
join -a1 month1 month2
:左外连接,显示左边所有记录
[root@localhost ~]# join -a1 month1 month2
1 一月 January
2 二月 February
3 三月 March
4 四月 April
5 五月 May
6 六月 June
7 七月 July
8 八月 August
9 九月 September
10 十月 October
11 十一月 November
12 十二月 December
13 十三月
join -a2 month1 month2
:右外链接,显示右边所有记录
[root@localhost ~]# join -a2 month1 month2
1 一月 January
2 二月 February
3 三月 March
4 四月 April
5 五月 May
6 六月 June
7 七月 July
8 八月 August
9 九月 September
10 十月 October
11 十一月 November
12 十二月 December
14 MonthUnknown
join -a2 -a1 month1 month2
:全外连接,显示左边和右边所有记录
[root@localhost ~]# join -a2 -a1 month1 month2
1 一月 January
2 二月 February
3 三月 March
4 四月 April
5 五月 May
6 六月 June
7 七月 July
8 八月 August
9 九月 September
10 十月 October
11 十一月 November
12 十二月 December
13 十三月
14 MonthUnknown
join -o 1.1 2.2 month1 month2
:指定输出字段
[root@localhost ~]# join -o 1.1 2.2 month1 month2
1 January
2 February
3 March
4 April
5 May
6 June
7 July
8 August
9 September
10 October
11 November
12 December
8 tr
translate,“翻译”,替换字符
-
-c
:complement,反选 -
-d
:删除匹配的字符
[root@localhost ~]# echo "abcdef" | tr a-z A-Z
ABCDEF
[root@localhost ~]# echo "abcdef" | tr -d abc
def