• 技术文章 >运维 >linux运维

    Linux tee命令详解

    藏色散人藏色散人2023-03-13 09:16:53原创63

    Linux tee命令的功能是从标准输入读取,再写入标准输出和文件,其使用语法是“tee [OPTION]... [FILE]...”,其中参数“-a --append”表示追加到文件,参数“-i --ignore-interrupts”表示忽略中断信号,参数“-p”表示诊断写入非管道的错误等。

    本教程操作环境:linux5.9.8系统、Dell G3电脑。

    linux 命令:tee 详解

    tee 的功能是从标准输入读取,再写入标准输出和文件。

    用法:tee [OPTION]... [FILE]...

    -a, --append 追加到文件

    -i, --ignore-interrupts 忽略中断信号

    -p 诊断写入非管道的错误

    --output-error[=MODE] 设置输出错误的方式,MODE 的选项在下边

    --help 帮助文档

    --version 版本信息

    MODE:

    warn 写入遇到错误时诊断

    warn-nopipe 写入非管道遇到错误时诊断

    exit 写入遇到错误时退出

    exit-nopipe 写入非管道遇到错误时退出

    如果没有指定 --output-error,tee 会在写入管道发生错误时立即退出,写入非管道时诊断。

    使用示例:

    默认功能和追加功能:

    [root@server dir]# echo 'This is a sentence.' | tee output
    This is a sentence.
    
    [root@server dir]# cat output
    This is a sentence.
    
    [root@server dir]# echo 'This is another sentence.' | tee -a output
    This is another sentence.
    
    [root@server dir]# cat output
    This is a sentence.
    This is another sentence.
    
    [root@server dir]# echo 'This is a unique sentence.' | tee output
    This is a unique sentence.
    
    [root@server dir]# cat output
    This is a unique sentence.

    同时写入两个文件:

    [root@server dir]# tee a b
    they have the same content
    they have the same content
    ^C
    [root@server dir]# cat a
    they have the same content
    [root@server dir]# cat b
    they have the same content
    相关推荐:《Linux视频教程

    以上就是Linux tee命令详解的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:linux tee
    上一篇:linux怎么显示文件最后几行 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • linux 宕机日志在哪• linux磁盘大小单位有哪些• Linux常用命令:cp命令实例练习• linux怎么显示文件最后几行
    1/1

    PHP中文网