2021-10-19 Linux tee 命令读入标准数据然后标准输出同时把数据写入文件,可以在终端上显示的同时保存到文件。

这篇博客介绍了Linux命令`tee`的使用,它能从标准输入读取数据并同时输出到标准输出以及指定的文件。`-a`选项用于追加内容到文件而不是覆盖。默认情况下,再次使用`tee`命令会覆盖原有文件内容。博客还提供了不同错误处理模式的说明,并给出了实际脚本使用的例子。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、man tee ,tee - read from standard input and write to standard output and files

命令读入标准数据然后标准输出同时把数据写入文件

TEE(1)                                                                  User Commands                                                                 TEE(1)

NAME
       tee - read from standard input and write to standard output and files

SYNOPSIS
       tee [OPTION]... [FILE]...

DESCRIPTION
       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.

AUTHOR
       Written by Mike Parker, Richard M. Stallman, and David MacKenzie.

二、我这里脚本上用到的地方。

 三、下面的截图展示了这个输出内容不仅被写入 output.txt 文件,也被显示在标准输出中。

 四、默认情况下,在同一个文件下再次使用 tee 命令会覆盖之前的信息。如果你想追加信息到文件的话,可以通过 -a 命令选项改变默认设置。

[command] | tee -a [file]

五、参考文章

技术|为初学者介绍的 Linux tee 命令(6 个例子)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值