2

This creates a file in the same directy as 'some.file.bak'.

find /home/ -ipath "*/temp/some.file" -type f  -exec cp {} {}.bak \;

How to make a copy in another name such as 'another.file' in the same directory as some.file instead of 'some.file.bak'.

2 Answers2

4

find /home/ -ipath "*/temp/some.file" -type f -execdir cp {} another.file \;

You just have to change exec to execdir from the other answer (sorry I cannot post it as a comment yet).

The execdir option states, according to find's man page:

-execdir command {} +

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find.

glenn jackman
  • 27,524
Isaac
  • 261
0
find /home/ -ipath "*/temp/some.file" -type f  -exec cp {} another.file \;