Linux基础学习笔记之tee命令

tee命令用于将数据重定向到文件,另一方面还可以提供一份重定向数据的副本作为后续命令的stdin.即把数据重定向给定义文件和屏幕上。
Linux基础学习笔记之tee命令_第1张图片

用法:
tee [-ai] 文件
选项:
-a:向文件中重定向时使用追加模式;
-i:忽略中断(interrupt)信号。
例如:
1.将last的输出存一份到last.list文件中

[root@centos6 highbashprogram]# last | tee last.list | cut -d " " -f1
    root
    root
    root
    root
    root
    root
    root
    root

    wtmp
    [root@centos6 highbashprogram]# cat last.list
    root     pts/0        192.168.118.1    Sun May 21 17:29   still logged in   
    root     pts/0        192.168.118.1    Sun May 21 16:26 - 16:30  (00:03)    
    root     pts/3        192.168.118.1    Mon May 22 01:14   still logged in   
    root     pts/4        192.168.118.1    Mon May 22 00:48 - 16:26  (-8:-21)   
    root     pts/3        192.168.118.1    Mon May 22 00:47 - 01:13  (00:26)    
    root     pts/2        192.168.118.1    Mon May 22 00:15 - 15:44  (-8:-31)   
    root     pts/2        192.168.118.1    Mon May 22 00:09 - 00:15  (00:05)    
    root     pts/0        192.168.118.1   
Sun May 21 23:43 - 15:26 (-8:-17)

wtmp begins Sun May 21 23:43:03 2017

2.向homefile文件中追加内容

[root@centos6 highbashprogram]# ls -l / | tee -a ~/homefile | more
total 108
drwxr-xr-x.   4 root root  4096 May 22  2017 app
dr-xr-xr-x.   2 root root  4096 May 17 14:34 bin
dr-xr-xr-x.   5 root root  4096 May 17 13:01 boot
drwxr-xr-x.  20 root root  3840 May 21  2017 dev
drwxr-xr-x. 123 root root 12288 May 21 15:11 etc
drwxr-xr-x.   3 root root  4096 May 17 14:33 home
dr-xr-xr-x.  11 root root  4096 May 17 12:55 lib
dr-xr-xr-x.   9 root root 12288 May 17 14:34 lib64
drwx------.   2 root root 16384 May 17 12:46 lost+found
drwxr-xr-x.   3 root root  4096 May 18 08:34 media
--More--

你可能感兴趣的:(linux基础学习)