美文网首页
Tee 使用场景

Tee 使用场景

作者: Williamzzl | 来源:发表于2016-11-04 13:18 被阅读0次

    Tee命令用来同时存储和展示其他命令的输出

    1. 输出到Console同时写入文件

    使用ls查看文件夹下内容:

    $ ls
    account  cache  crash 
    

    同时需要保存到文件filelist.txt(否者需要ls > filelist.txt):

    $ ls | tee filelist.txt
    account
    cache
    crash
    filelist.txt
    

    查看filelist.txt中,会看到包含了上一条命令的输出:

    2. 输出使用在多条命令中:

    查看并备份当前crontab后,更新crontab内容(old->new)

    $ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab
    
    3. 使用append(默认覆盖)
    $ ls | tee –a file
    

    4, 多文件写

    $ ls | tee file1 file2 file3
    

    相关文章

      网友评论

          本文标题:Tee 使用场景

          本文链接:https://www.haomeiwen.com/subject/jbniuttx.html