2013-03-07 136 views
0

我有兩個文件夾:一個包含.dwg文件和其他.pdf文件。我的文件夾中的樹不同。Bash腳本複製文件

如何在具有相同名稱的DXF附近複製PDF?例如,我有文件/1/2/3/1.pdf複製到/6/4/5/5/,我發現我已經試過這個文件1.dxf

for DIR in $source 
do 
     for LISTE in `find $DIR -type f -name '*.PDF' -or -name '*.pdf' ` 
     do 
       find $dest -type f -name {} -exec ****** {} \; 
     done 
done 

我的問題是我不知道如何從find $dest -type f得名。

+0

有'basename'去除目錄路徑,但我沒有完全理解這個 – Raffaele 2013-03-07 12:32:01

+0

旁邊的問題,我建議你看看[這個問題](http://unix.stackexchange.com/q/9496/33747)真正理解用shell移動文件有多棘手。這可能是一個很好的學習練習,但對我來說,腳本語言對於這類問題總是更好 – Raffaele 2013-03-07 13:00:17

回答

0

「我的問題是我不知道如何從find $ dest -type f得到一個名字。」

使用-printf選項find

find ${dest} -type f -printf "%f\n" 

man find

-printf format 
     True; print format on the standard output, 
     interpreting `\' escapes and `%' directives. 

...

%f  File's name with any leading directories removed (only the last element).