Print on terminal and into file simultaneously?

后端 未结 3 1358
臣服心动
臣服心动 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
    
    0 讨论(0)
  • 2020-12-15 15:28

    Does exactly your thing

    http://linux.die.net/man/1/tee

    0 讨论(0)
  • 2020-12-15 15:30

    Pipe your output to the tee command.

    Example:

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

    Note that the stdout of echo is printed out as well as written to the file specified by thr tee command.

    0 讨论(0)
提交回复
热议问题