博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
8.12 tee_tr_split命令
阅读量:6906 次
发布时间:2019-06-27

本文共 3374 字,大约阅读时间需要 11 分钟。

hot3.png

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.txtasda123 fgdg,451abccdaabc1[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
        • 若不写单位,会默认是字节
    • -l行数
      • 格式:split -l 1000 bigfile
[root@hf-01 ~]# find /etc/ -type f -name "*conf" -exec cat {} >>a.txt \;    //将etc目录下所有文件以conf结尾的文件全都输出重定向到a.txt文件中[root@hf-01 ~]# du -sh a.txt252K	a.txt[root@hf-01 ~]# mv a.txt 111/    //把a.txt文件移动到111目录下[root@hf-01 ~]# cd 111/            //切换到111目录下[root@hf-01 111]# lsa.txt[root@hf-01 111]# split -b 1000 a.txt    //单位是字节(1000byte=1k)[root@hf-01 111]# lsa.txt  xbe  xcj  xdo  xet  xfy  xhd  xii  xjn  xks  xlx  xnc  xoh  xpm  xqr  xrw  xtbxaa    xbf  xck  xdp  xeu  xfz  xhe  xij  xjo  xkt  xly  xnd  xoi  xpn  xqs  xrx  xtcxab    xbg  xcl  xdq  xev  xga  xhf  xik  xjp  xku  xlz  xne  xoj  xpo  xqt  xry  xtdxac    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.txt4.0K	xaa4.0K	xab4.0K	xac4.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]# lsa.txt  xaa  xab  xac[root@hf-01 111]# du -sh *252K	a.txt100K	xaa100K	xab52K	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]# lsabcaa  abcab  abcac  a.txt[root@hf-01 111]# split -b 100k a.txt abc.[root@hf-01 111]# lsabcaa  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]#

转载于:https://my.oschina.net/u/3707314/blog/1574939

你可能感兴趣的文章
WinAPI: waveOutPause - 暂停播放
查看>>
FTP自动上传
查看>>
我的友情链接
查看>>
mysqldump工具
查看>>
用 PHP 读取文件的正确方法
查看>>
LoadRunner压力测试时监控服务器Linux的资源情况
查看>>
azure存储并发写 压力测试
查看>>
管理用户和用户权限
查看>>
VCTransitionsLibrary –自定义iOS交互式转场动画的库
查看>>
final、static(Java)和const、static(C#)
查看>>
C语言利用中心极限定理产生高斯白噪声
查看>>
电脑定时关机
查看>>
Disconf-Web管理端安装
查看>>
PHP-防止SQL注入
查看>>
Javascript监听 ESC按下事件
查看>>
Comet技术详解:基于HTTP长连接的Web端实时通信技术
查看>>
MongoDB:Ruby中嵌入Javascript实战
查看>>
亚马逊云服务与IT的未来:微博速递
查看>>
博客收藏
查看>>
关于ant-design表单问题
查看>>