簡體   English   中英

在Linux中查找並執行命令。 是否可以通過管道2 find和exec命令

[英]Find and exec command in linux. Is it possible to pipe 2 find and exec commands

我正在嘗試完成這項任務

1)找到目錄A(DIR_A),並將目錄中的所有文件(包括其子目錄,如有)復制到新目錄DIR_B中

2)在目錄(DIR_B)中,用橙色替換單詞apple

我執行了以下代碼,由於某種原因,它復制了所有文件,但是在第二項任務上失敗了(將蘋果替換為橙色)。 我將不勝感激。 下面是我的代碼

find DIR_A -iname FILEA -type f -exec cp {} DIR_B \;|find DIR_B/ -iname \*.* -type f -exec sed -i "s|apple|orange|g" {} \;

嘗試這個 :
Sed語法:
sed's / old / new / g'

 find DIR_A -iname FILEA -type f -exec cp {} DIR_B \;|find DIR_B/ -iname \*.* -type f -exec sed -i "s/apple/orange/g" {} \;

與其嘗試將一個查找結果的輸出傳遞到另一個查找結果,不如不按順序運行它們? 我不確定find從其stdin中讀取。

find DIR_A -iname FILEA -type f -exec cp {} DIR_B \; ; find DIR_B/ -iname \*.* -type f -exec sed -i "s|apple|orange|g" {} \;

我用分號代替了你的煙斗。

暫無
暫無

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

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