zoukankan      html  css  js  c++  java
  • Tee命令使用实例

    tee命令用于读取标准输入的数据,将内容输出到屏幕,同时保存成文件,并且可以保存到多个文件。
    如何使用tee

    tee最基本的用法就是显示输出结果并且保存内容到文件中。下面例子使用free命令显示系统内存使用信息,并使用tee命令将信息输出到屏幕,并保存到文件mem.txt中。

    [root@localhost ~]# free -h | tee mem.txt
                  total        used        free      shared  buff/cache   available
    Mem:           1.8G        164M        1.2G        9.6M        387M        1.5G
    Swap:          2.0G          0B        2.0G
    

    可以查看一下mem.txt文件,可以看到输出内容已经保存到mem.txt里面了。
    Linux中Tee命令使用实例Linux中Tee命令使用实例

    写入到多个文件

    tee可以写入多个文件,每个文件之间使用空格分隔。

    [root@localhost ~]# free -h | tee mem1.txt mem2.txt mem3.txt
                  total        used        free      shared  buff/cache   available
    Mem:           1.8G        165M        1.2G        9.6M        389M        1.5G
    Swap:          2.0G          0B        2.0G
    

    Linux中Tee命令使用实例Linux中Tee命令使用实例

    在已存在的文件底部追加内容

    下面的例子使用选项-a在文件底部追加内容,不覆盖原有内容。

    [root@localhost ~]# free -h | tee -a mem.txt
                  total        used        free      shared  buff/cache   available
    Mem:           1.8G        165M        1.2G        9.6M        389M        1.5G
    Swap:          2.0G          0B        2.0G
    

    可以看到,在mem.txt文件底部追加了新的内容。
    Linux中Tee命令使用实例Linux中Tee命令使用实例
    如果不想在屏幕输出内容,可以使用>标准输出符号,重定向到/dev/null中:

    [root@localhost ~]# free -h | tee -a mem.txt > /dev/null 
    
    总结

    tee命令用于读取标准输入的数据,将内容输出到屏幕,同时保存成文件,并且可以保存到多个文件。

  • 相关阅读:
    破解 inode 校园网多网卡限制方法
    更改 eclipse的 workplace路径
    VMware Network Adapter VMnet1和VMnet8 未识别的网络的解决方法
    eclipse更改xml文件,txt文件,property文件等文件编辑器的字体设置
    Lua中数组全排序
    Lua尾调用
    C++ 调用Lua简单例子
    linux生成core dump
    vc获取系统日期
    C++培训第一天
  • 原文地址:https://www.cnblogs.com/linuxprobe/p/14523436.html
Copyright © 2011-2022 走看看