1

I've some new files in a folder A. I want to replace the old files which are located in different folders (ex. B, C, D), with the new files. Is there any way to do this in one shot by writing some script in Mac OS?

For example, the new files are located in /Updatede, and have names such as: flower1.jpg, flower2.jpg, flower3.jpg.

Now I want to replace below old files

/Workarea/AssetGroupOne/flower1.jpg 
/Workarea/AssetGroupTwo/flower2.jpg 
/Workarea/AssetGroupThree/flower3.jpg
/Workarea/AssetGroupSix/flower1.jpg

I want to be specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg

Note: I have more files, but for the sake of brevity, I have not listed them all here.

Shubham
  • 111

2 Answers2

2

Try this,

#!/bin/bash
cd /Updated &&
for i in *
do
        find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} \;
done
terdon
  • 242,166
Siva
  • 9,077
0
#!/bin/bash
cd /Updated
mv flower1.jpg /Workarea/AssetGroupOne/
mv flower2.jpg /Workarea/AssetGroupTwo/
mv flower3.jpg /Workarea/AssetGroupThree/

I wonder though, writing the script takes longer than just moving the files in Finder (or typing the commands above into the command line).

nohillside
  • 3,251
  • I need to do this repeatedly for several files. – Shubham Jan 04 '19 at 13:57
  • @Shubham we can't help you if you give us a small piece of information every time. Edit your question and explain what you actually need. How can we know what files need to be moved where? – terdon Jan 04 '19 at 14:11
  • 1
    I am assuming the OP did not bore us with the 1000s of screen fulls of file names, as it would have added nothing to understanding (except to say there is to much to do manually). – ctrl-alt-delor Jan 04 '19 at 18:24
  • @ctrl-alt-delor Which is why the answer by msp9011 probably is on the right track by figuring out where the updated files belong to. – nohillside Jan 04 '19 at 18:27
  • @ctrl-alt-delor an indication of whether the files in /Updated are in a single directory, of whether they all need to be copied, if there can be file name collisions, if multiple files with the same name can be in different Workarea directories, and such details would be helpful. – terdon Jan 04 '19 at 19:44
  • @terdon I've added some more information to my question. – Shubham Jan 07 '19 at 06:56