I have a folder structureconf/    widget1/        env1.cfg        env2.cfg    widget2/        env1.cfg        env2.cfg    widget3/        env1.cfg        env2.cfg    widget4/        env1.cfg        env2.cfg    ...What I want to do is find all the files named env2.cfg, and create a copy of them in their directory named env3.cfg.I've tried:find -name env2.cfg -exec cp '{}' env3.cfg ;but that just created env3.cfg in the conf/ directory.Any thoughts?For clarification I'm doing this on Mac OSX, but ideally the same command should work on CentOS if possible.
How do I create a copy of a file in multiple directories?
find;cp;exec
Tryfind . -name env2.cfg -execdir cp {} env3.cfg \;By replacing exec to execdir. It will mean that your 'action' (cp) will take place inside the folder where the file (env2.cfg) have been found.