Linux Tee命令教程,以及标准输出管理示例

Linux and Unix operating systems mainly managed through command line interface. For complex situations we generally run multiple commands where each command’s output can be input of other commands. Linux provides very useful tool named tee which provides some flexibility while redirecting command outputs.

Linux和Unix操作系统主要通过命令行界面进行管理。 对于复杂的情况,我们通常会运行多个命令,其中每个命令的输出都可以输入其他命令。 Linux提供了一个非常有用的工具tee ,它在重定向命令输出时提供了一定的灵活性。

将输出写入文件 (Write Output To A File)

One of the most popular use case of tee command is writing command outputs into a file. In this case we will write ls / command output into file nameddirlist and also print output to the terminal.

tee命令最流行的用例之一是将命令输出写入文件。 在这种情况下,我们会将ls /命令输出写入名为dirlist并将输出输出到终端。

$ ls / | tee dirlist
Write Output To A File
Write Output To A File
将输出写入文件

将输出追加到文件(Append Output To A File)

In previous example we have created a file and added provided output. Default behaviour is overwriting to the given file. But in some situations we need to append to the file. We can provide -a option which will append to the given file.

在前面的示例中,我们创建了一个文件并添加了提供的输出。 默认行为是覆盖给定文件。 但是在某些情况下,我们需要附加到文件中。 我们可以提供-a选项,该选项将附加到给定文件中。

$ ls / | tee -a dirlist

写入输出多个文件 (Write Output Multiple Files)

We have the ability to write output multiple files. In this example we will write output to the files named f1 , f2 , f3 , … . We can also add more files.

我们有能力写输出多个文件。 在此示例中,我们将输出写入名为f1f2f3 …的文件。 我们还可以添加更多文件。

$ ls / | tee f1 f2 f2

忽略中断 (Ignore Interrupts)

What if there is an interrupt against tee . By default the operation and command execution will be finished. We can ignore these interrupts with -i option like below.

如果对tee有干扰,该怎么办。 默认情况下,操作和命令执行将完成。 我们可以使用-i选项忽略这些中断,如下所示。

$ ls / | tee -i f1
LEARN MORE  How To Linux Bash For Loop In Files?
了解更多信息如何在Linux Bash中循环文件?

翻译自: https://www.poftut.com/linux-tee-command-tutorial-examples-stdout-management/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值