2013-03-07 138 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).