简体   繁体   中英

Bash script copy a files

I have two folders: one contains .dwg files and the other .pdf files. The tree in my folders is different.

How can I copy a PDF near a DXF that has the same name? For example I have to copy the file /1/2/3/1.pdf to /6/4/5/5/ where I found the file 1.dxf

I ve tried this :

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

My problem is I don't know how to get a name from find $dest -type f .

"My problem is I don't know how to get a name from find $dest -type f."

Use the -printf option of find :

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

See 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). 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM