簡體   English   中英

在終端上打印並同時打印到文件中?

[英]Print on terminal and into file simultaneously?

我有一個shell腳本來壓縮一些數據..我想將結果打印到一個文件中,但這樣做會阻止結果顯示在終端上。 有沒有一種方法可以在屏幕上打印結果並寫入文件。 提前致謝。

將輸出傳遞給tee命令。

例:

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

請注意, echo的stdout將打印出來並寫入thr tee命令指定的文件中。

請注意,您可以將-a標志添加到tee以附加到輸出文件

[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

完全是你的事

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM