前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tee命令

tee命令

作者头像
cultureSun
发布2023-05-18 14:19:51
4870
发布2023-05-18 14:19:51
举报
文章被收录于专栏:cultureSun学安全cultureSun学安全

简介

将标准输入复制到每个文件中,也复制到标准输出。

详解

帮助文档

代码语言:javascript
复制
# tee --help  
Usage: tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.

  -a, --append              append to the given FILEs, do not overwrite
  -i, --ignore-interrupts   ignore interrupt signals
  -p                        diagnose errors writing to non pipes
      --output-error[=MODE]   set behavior on write error.  See MODE below
      --help     display this help and exit
      --version  output version information and exit

MODE determines behavior with write errors on the outputs:
  'warn'         diagnose errors writing to any output
  'warn-nopipe'  diagnose errors writing to any output not a pipe
  'exit'         exit on error writing to any output
  'exit-nopipe'  exit on error writing to any output not a pipe
The default MODE for the -p option is 'warn-nopipe'.
The default operation when --output-error is not specified, is to
exit immediately on error writing to a pipe, and diagnose errors
writing to non pipe outputs.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/tee>
or available locally via: info '(coreutils) tee invocation'

Bash

参数详解

-a, --append

追加到给出的文件,而不是覆盖

-i, --ignore-interrupts

忽略中断信号

-p

对写入非管道的行为排查错误 [ -p 选项的默认模式是“warn-nopipe”。]

--output-error[=模式]

设置写入出错时的行为。见下面“模式”部分

--help

显示此帮助信息并退出

--version

显示版本信息并退出

模式详解

warn'

对向任何文件输出出错的情况进行诊断

'warn-nopipe'

对向除了管道以外的任何文件输出出错的情况进行诊断

'exit'

一旦输出出错,则退出程序

'exit-nopipe'

一旦输出出错且非管道,则退出程序

默认

当 --output-error 没有给出时,默认的操作是在向管道写入出错时立刻退出,且在向非管道写入出错时对问题进行诊断。

实例

代码语言:javascript
复制
┌──(root㉿kali)-[~/Desktop]
└─# tee test.txt         
this is a example.           #这行是控制台自己键盘输入的
this is a example.           #这行是tee输出到控制台的
^C                           #ctrl+c 退出tee命令
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# cat test.txt             #输出test.txt文件
this is a example.
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# tee test.txt tt.txt      #同时向test.txt、tt.txt两个文件写入
this is a other example.     #这行是控制台自己键盘输入的
this is a other example.     #这行是tee输出到控制台的
^C                           #ctrl+c 退出tee命令
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# cat test.txt             #输出test.txt文件,可见覆盖了原内容
this is a other example.
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# cat tt.txt               #输出tt.txt文件
this is a other example.    
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# tee -a test.txt          # -a 参数,追加内容
this is a example.           #这行是控制台自己键盘输入的
this is a example.           #这行是tee输出到控制台的
^C                           #ctrl+c 退出tee命令
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# cat test.txt             #输出test.txt文件,可见没有覆盖原内容,追加到下一行
this is a other example.
this is a example.
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# echo `date` | tee -a test.txt      #利用管道符将日期追加到test.txt,同时输出到控制台     
Fri Oct 7 11:21:09 PM EDT 2022
                                                                                                                          
┌──(root㉿kali)-[~/Desktop]
└─# cat test.txt         #输出test.txt文件             
this is a other example.
this is a example.
Fri Oct 7 11:21:09 PM EDT 2022

Bash

结束语

tee命令是在学习过程中遇到的,感觉有意思且实用,故记录一下。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
  • 详解
    • 帮助文档
      • 参数详解
        • 模式详解
          • 实例
          • 结束语
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档