Print on terminal and into file simultaneously?

后端 未结 3 1411
臣服心动
臣服心动 2020-12-15 14:55

I have a shell script that greps some data.. I want to print the result into a file, but doing that prevents the result being displayed on the terminal. Is there a way that

3条回答
  •  孤街浪徒
    2020-12-15 15:28

    Note you can add the -a flag to tee to append to the output file

    [me@home]$ echo hello | tee out.txt
    hello
    [me@home]$ echo hello again | tee -a out.txt
    hello again
    [me@home]$ cat out.txt
    hello
    hello again
    

提交回复
热议问题