2017-04-13 41 views
0

我想複製一個文件中都存在,其中一個腳本文件中所有子目錄我想其中一個腳本文件中所有子目錄

我試過這個命令存在複製文件

find . -type f -regex '.*.sh' -exec echo cp myfile.txt {} \; 

輸出是

cp myfile.txt ./b/e/e.sh 
cp myfile.txt ./a/a.sh 
cp myfile.txt ./c/f/f.sh 
cp myfile.txt ./c/c.sh 

我所要的輸出是

cp myfile.txt ./b/e 
cp myfile.txt ./a 
cp myfile.txt ./c/f 
cp myfile.txt ./c 

我該如何改變find命令的輸出來實現這個功能?

感謝

+1

爲什麼你需要的輸出忽略'f.sh'和'C .sh'? –

+0

我不想忽視它們,但我沒有用f.sh和c.sh寫這兩行,抱歉讓我感到困惑。 – naren

+0

@WilliamPursell,我現在編輯了這個問題。 – naren

回答

1

也許不是最優雅的方式,而是:

.... -exec bash -c 'cp myfile.txt $(dirname {})' \; 

這裏是另一個問題:

find . -regex '.*.sh' -exec dirname {} \; | xargs -n 1 cp myfile.txt 
+0

謝謝,它的工作原理。 – naren

相關問題