tee命令
- 清空文件内容 >1.txt
[root@hf-01 ~]# > 2.txt
[root@hf-01 ~]# cat 2.txt
[root@hf-01 ~]#
- tee命令和输出重定向>类似,重定向的同时还在屏幕显示
- tee命令,就是重定向,把前面命令输出的结果打印到屏幕上
- -a参数,追加重定向
[root@hf-01 ~]# cat 3.txt
asda
123 fgdg,45
1
abc
cda
abc
1
[root@hf-01 ~]# sort 3.txt |uniq -c |tee a.txt
2 1
1 123 fgdg,45
2 abc
1 asda
1 cda
[root@hf-01 ~]# cat a.txt
2 1
1 123 fgdg,45
2 abc
1 asda
1 cda
[root@hf-01 ~]#
tee命令参数-a
- tee -a 就是追加重定向
[root@hf-01 ~]# sort 3.txt |uniq -c |tee -a a.txt
2 1
1 123 fgdg,45
2 abc
1 asda
1 cda
[root@hf-01 ~]# cat a.txt
2 1
1 123 fgdg,45
2 abc
1 asda
1 cda
2 1
1 123 fgdg,45
2 abc
1 asda
1 cda
[root@hf-01 ~]#
tr命令
- tr 命令,用来替换字符的命令,tr 'a' 'b',大小写替换tr '[a-z]' '[A-Z]'
- 支持写多个字符替换
[root@hf-01 ~]# echo "hanfeng" |tr '[hf]' '[HF]'
HanFeng
[root@hf-01 ~]# echo "hanfeng" |tr 'h' 'H'
Hanfeng
[root@hf-01 ~]# echo "hanfeng" |tr '[a-z]' '[A-Z]'
HANFENG
[root@hf-01 ~]#
- 字符替换数字的时候,需要注意格式
- 替换数字的时候,需要去除方括号[]
[root@hf-01 ~]# echo "hanfeng" |tr '[a-z]' '[1]' //错误示范,这样写会出错
]1]]]]]
[root@hf-01 ~]# echo "hanfeng" |tr '[a-z]' '1' //在替换成数字的时候,需要去除方括号
1111111
[root@hf-01 ~]#
split命令
- split 切割,将一个大文件切割成很多个小文件
- -b大小(默认单位字节)
- 格式:split -b 100M bigfile
- 若不写单位,会默认是字节
- 格式:split -b 100M bigfile
- -l行数
- 格式:split -l 1000 bigfile
- -b大小(默认单位字节)
[root@hf-01 ~]# find /etc/ -type f -name "*conf" -exec cat {} >>a.txt \; //将etc目录下所有文件以conf结尾的文件全都输出重定向到a.txt文件中
[root@hf-01 ~]# du -sh a.txt
252K a.txt
[root@hf-01 ~]# mv a.txt 111/ //把a.txt文件移动到111目录下
[root@hf-01 ~]# cd 111/ //切换到111目录下
[root@hf-01 111]# ls
a.txt
[root@hf-01 111]# split -b 1000 a.txt //单位是字节(1000byte=1k)
[root@hf-01 111]# ls
a.txt xbe xcj xdo xet xfy xhd xii xjn xks xlx xnc xoh xpm xqr xrw xtb
xaa xbf xck xdp xeu xfz xhe xij xjo xkt xly xnd xoi xpn xqs xrx xtc
xab xbg xcl xdq xev xga xhf xik xjp xku xlz xne xoj xpo xqt xry xtd
xac xbh xcm xdr xew xgb xhg xil xjq xkv xma xnf xok xpp xqu xrz xte
等等等,只截取了一小部分
[root@hf-01 111]# du -sh //查看目录下文件大小
2.3M .
[root@hf-01 111]# du -sh * //会看到分割出来的都占据了一个块
252K a.txt
4.0K xaa
4.0K xab
4.0K xac
4.0K xad
等等等,只截取了一小部分
[root@hf-01 111]# rm -f x*
在切割一个文件,在不指定任何的文件名,最后显示的切割完的文件,会是已xab,xac这样一直延续下去,若再切割一次,则会zxaaa,zxaab等依次下去
- split -b指定单位大小切割
[root@hf-01 111]#
[root@hf-01 111]# split -b 100k a.txt
[root@hf-01 111]# ls
a.txt xaa xab xac
[root@hf-01 111]# du -sh *
252K a.txt
100K xaa
100K xab
52K xac
[root@hf-01 111]# rm -f x*
[root@hf-01 111]#
- 指定文件大小的同时,指定文件的名称
[root@hf-01 111]# split -b 100k a.txt abc
[root@hf-01 111]# ls
abcaa abcab abcac a.txt
[root@hf-01 111]# split -b 100k a.txt abc.
[root@hf-01 111]# ls
abcaa abc.aa abcab abc.ab abcac abc.ac a.txt
[root@hf-01 111]# rm -f abc*
切割的文件默认是以x开头!!!
split命令的参数-l
- split -l 指定行数
[root@hf-01 111]# split -l 1000 a.txt
[root@hf-01 111]# ls -l
总用量 512
-rw-r--r--. 1 root root 256144 11月 18 06:41 a.txt
-rw-r--r--. 1 root root 44741 11月 18 06:59 xaa
-rw-r--r--. 1 root root 44239 11月 18 06:59 xab
-rw-r--r--. 1 root root 44320 11月 18 06:59 xac
-rw-r--r--. 1 root root 34153 11月 18 06:59 xad
-rw-r--r--. 1 root root 38618 11月 18 06:59 xae
-rw-r--r--. 1 root root 34693 11月 18 06:59 xaf
-rw-r--r--. 1 root root 15380 11月 18 06:59 xag
[root@hf-01 111]# wc -l *
6548 a.txt
1000 xaa
1000 xab
1000 xac
1000 xad
1000 xae
1000 xaf
548 xag
13096 总用量
[root@hf-01 111]#