簡體   English   中英

linux:如何重定向到文件和另一個進程

[英]linux : how to redirect to a file and to another process

我的命令如下

cmd1 | cmd2 | cmd3

我需要先查看命令輸出,然后再將其傳遞給另一個進程。 我怎樣才能做到這一點?

如果我用

cmd1 > file1 | cmd2 | cmd3

我想我必須在cmd2的過程中管理從文件讀取,但是我想要的是傳遞的標准輸出引發不同的命令,並查看傳遞的異常。

看一下tee命令。 這可能是您要尋找的。 例:

cmd1 | tee file1 | cmd2 | cmd3

如前所述,您可以在執行的命令之間將tee/dev/tty用作其參數:

ls -l  | tee /dev/tty | grep one_file -A2 | tee /dev/tty | grep something_else

您可以使用tee命令:

tee - read from standard input and write to standard output and files

例:

echo hi | tee 1.txt | cat -n | tee 2.txt | grep hi

暫無
暫無

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

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