How to make a copy of file in the same directory

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'.

13th Matrix

Posted 2014-09-26T08:22:52.950

Reputation: 73

Answers

3

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.

Isaac

Posted 2014-09-26T08:22:52.950

Reputation: 241

+1 I came up with a convoluted solution passing {} into a shell. This is an excellent answer: the solution and the documentation. – glenn jackman – 2014-09-26T10:38:44.553

0

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

Peter Lamby

Posted 2014-09-26T08:22:52.950

Reputation: 362

i tried that earlier but cp copy another.file into the directory i run the script not the directory as some.file which i want. Sorry, i should have elaborated same directory as some.file. – 13th Matrix – 2014-09-26T08:38:23.913