Print on terminal and into file simultaneously?

后端 未结 3 1405
臣服心动
臣服心动 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: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.

提交回复
热议问题