博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux tee命令_Linux tee命令示例
阅读量:2528 次
发布时间:2019-05-11

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

linux tee命令

In this article, we shall go through the tee command in Linux. This is commonly used to read the input and write to both the Standard Output (stdout) and to one or more files.

在本文中,我们将介绍Linux中的tee命令。 这通常用于读取输入并写入标准输出(stdout)和一个或多个文件。

The tee command is commonly used along with other commands through the pipe (|) operator.

tee命令通常与其他通过管道( | )运算符使用的命令一起使用。

Let us understand how this command works through a few examples.

让我们通过几个示例来了解此命令的工作方式。



Linux tee命令语法 ( Linux tee Command Syntax)

The tee command is used with the following syntax:

tee命令使用以下语法:

tee [-OPTIONS] [FILES]
  • -OPTIONS represent the various possible options along with the tee command.

    -OPTIONS代表各种可能的选项以及tee命令。
  • FILES represent all the files that tee writes the output data to, along with stdout.

    FILES代表所有将输出数据写入tee的文件,以及stdout


tee命令选项 (tee Command Options)

There are different options for the tee command that changes the behavior of the command. The below table summarizes this for us.

tee命令有不同的选项可以更改命令的行为。 下表为我们总结了这一点。

Tee Command Options
Tee Command Options
Tee命令选项


tee命令在Linux中的用法 (Usage of tee Command in Linux)

1.写入多个文件 (1. Write to multiple files)

The most simple usage of this command would be to write to both the stdout and to all the given files. But since we need to give input to stdin of tee, it is commonly used in a pipeline sequence.

此命令最简单的用法是同时向stdout和所有给定文件写入数据。 但是由于我们需要将输入提供给tee的 stdin ,因此它通常在管道序列中使用。

The below example shows this:

以下示例显示了这一点:

echo 'HELLO WORLD' | tee out1.txt out2.txt

This echoes HELLO WORLD and redirects the stdout using the pipe operator and passes it into tee. We will get the string HELLO WORLD written to both the Console, as well as to out1.txt and out2.txt.

这回显HELLO WORLD,并使用管道运算符重定向stdout并将其传递到tee 。 我们将把字符串HELLO WORLD以及同时写入out1.txtout2.txt的字符串都写入控制台。

Output

输出量

Linux Tee Command Basic Example
Linux Tee Command Basic Example
Linux Tee命令基本示例

2.附加到多个文件 (2. Append to multiple files)

By default, the tee command overwrites the files specified as arguments. To avoid that, we can use the -a (--append) option to append to those files instead.

缺省情况下,tee命令将覆盖指定为参数的文件。 为避免这种情况,我们可以使用-a (-- --append )选项来附加到这些文件。

echo 'HELLO WORLD PART 2' | tee -a out1.txt out2.txt

Output

输出量

Linux Tee Command Append
Linux Tee Command Append
Linux Tee命令附件

3.忽略中断 (3. Ignore Interrupts)

We can use the -i option to ignore any interrupt signals (such as Ctrl+C) during the execution of tee.

我们可以使用-i选项在执行tee忽略任何中断信号(例如Ctrl + C )。

command | tee -i out.txt

4.隐藏控制台输出 (4. Hide the Console Output)

We can hide the output to the Console by redirecting the stdout of tee to /dev/null.

通过将tee的stdout重定向到/dev/null我们可以将输出隐藏到控制台。

ls -l | tee out3.txt > /dev/null

This sequence writes the output of ls -l to out3.txt, without printing to the Console.

此序列将ls -l的输出写入out3.txt ,而不打印到控制台。

Output

输出量

Linux Tee Command Hide Console Output
Linux Tee Command Hide Console Output
Linux Tee命令隐藏控制台输出


结论 (Conclusion)

In this article, we learned about the usage of the tee command in Linux, which is very useful for writing to multiple files. It is commonly used in a pipeline sequence, where you want to look at the intermediate output by printing to stdout.

在本文中,我们了解了tee命令在Linux中的用法,这对于写入多个文件非常有用。 它通常用于管道序列中,在该序列中,您希望通过打印到stdout来查看中间输出。

We learned about how we can use the tee command with various options. I hope this helped you understand more about the tee command, which can be a very nifty tool for a programmer!

我们了解了如何在各种选项中使用tee命令。 我希望这可以帮助您了解有关tee命令的更多信息,对于程序员来说,这可能是一个非常漂亮的工具!

参考资料 (References)



翻译自:

linux tee命令

转载地址:http://wulzd.baihongyu.com/

你可能感兴趣的文章
自动测试用工具
查看>>
前端基础之BOM和DOM
查看>>
[T-ARA/筷子兄弟][Little Apple]
查看>>
编译Libgdiplus遇到的问题
查看>>
【NOIP 模拟赛】Evensgn 剪树枝 树形dp
查看>>
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>