优势

  • 相对于 重定向 操作符 > 和 >>

    1. 功能更多
    2. 权限丰富

功能

把 命令行获取到的输入,输出到文件

可以接受的输入类型:

  • stdin
  • stdout
  • Pipe 管道结果

类似 >

  • 管道

    1
    
      echo hello | tee /path/to/my_file.txt
  • heredoc

    1
    2
    3
    4
    5
    
      tee my_file.txt <<-EOF
      hello line one
      line second
      line three
      EOF
  • stdin

    1
    
      tee my_file.txt < /etc/passwd
    • 把 /etc/passwd 作为 stdin 传给 tee, tee 再导入 my_file.txt

类似 >>

eg:

1
tee -a my_file.txt < /etc/passwd