1

I have the following tree struture.

sl_top
|       |-- Pinmux_Formal_checklist
|       |   |-- Pinmux_Formal_checklist.config
|       |   |-- Pinmux_Formal_checklist.html
|       |   `-- rev1
|       |       |-- rev1.config
|       |       `-- rev1.html
|       |-- checklist10
|       |   |-- checklist10.config
|       |   |-- checklist10.html
|       |   `-- rev2
|       |       |-- rev2.config
|       |       `-- rev2.html
|       |-- checklist13
|       |   |-- checklist13.config
|       |   |-- checklist13.html
|       |   `-- rev2
|       |       |-- rev2.config
|       |       `-- rev2.html

Here checklist 13 and checklist 10 have same file name and which am copying .html files to Another location.How can i save the both copies using linux command.

Command which i have tried?

find . -name '*.html' -exec cp -prv '{}' 'projects/html_files' ';

Obatined output:

rev1.html
rev2.html

Expected output:

rev1.html(Pinmux_Formal_checklist.html)
rev2.html(checklist10)
rev2.html(checklist13)

Note:In bracket it should show the respected directory name

1

If this writes the cp commands you expect, remove the echo from the line:

find . -name '*.html' -exec /bin/sh -c 'file="{}"; echo cp -prv "$file" "projects/html_files/${file##*/}(${file%/*})"' \;
  • the above command is just printing in the terminal none is copied to destination location. @Philippos – nasa aneer Jun 29 '17 at 9:47
  • Exactly, that's for safety. But if it's printing the commands you expect, remove the echo as I wrote; than it will really be copying – Philippos Jun 29 '17 at 9:48
  • It throws error for me as no such file directory.But am there in respected directory @Philippos – nasa aneer Jun 29 '17 at 9:59
  • Doesn't the message include the path name that was not found? Was the path in the echoed cp command correct? – Philippos Jun 29 '17 at 11:53
  • yes everything is correct @Philippos – nasa aneer Jun 29 '17 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.