How to replace multiple old file located at different location with the new files in Mac OS using script?
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.
scripting macintosh
add a comment |
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.
scripting macintosh
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Are you sure about the directories starting with/
? Aren't they located in your users home folder?
– nohillside
Jan 4 at 13:59
So how can we know what the target of each file is? How can we know that/Updated/flower1.jpg
should replace only/Workarea/AssetGroupOne/flower1.jpg
and not/Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?
– terdon♦
Jan 7 at 9:01
add a comment |
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.
scripting macintosh
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.
scripting macintosh
scripting macintosh
edited Jan 7 at 6:54
Shubham
asked Jan 4 at 13:07
ShubhamShubham
1064
1064
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Are you sure about the directories starting with/
? Aren't they located in your users home folder?
– nohillside
Jan 4 at 13:59
So how can we know what the target of each file is? How can we know that/Updated/flower1.jpg
should replace only/Workarea/AssetGroupOne/flower1.jpg
and not/Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?
– terdon♦
Jan 7 at 9:01
add a comment |
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Are you sure about the directories starting with/
? Aren't they located in your users home folder?
– nohillside
Jan 4 at 13:59
So how can we know what the target of each file is? How can we know that/Updated/flower1.jpg
should replace only/Workarea/AssetGroupOne/flower1.jpg
and not/Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?
– terdon♦
Jan 7 at 9:01
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Are you sure about the directories starting with
/
? Aren't they located in your users home folder?– nohillside
Jan 4 at 13:59
Are you sure about the directories starting with
/
? Aren't they located in your users home folder?– nohillside
Jan 4 at 13:59
So how can we know what the target of each file is? How can we know that
/Updated/flower1.jpg
should replace only /Workarea/AssetGroupOne/flower1.jpg
and not /Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?– terdon♦
Jan 7 at 9:01
So how can we know what the target of each file is? How can we know that
/Updated/flower1.jpg
should replace only /Workarea/AssetGroupOne/flower1.jpg
and not /Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?– terdon♦
Jan 7 at 9:01
add a comment |
2 Answers
2
active
oldest
votes
Try this,
#!/bin/bash
cd /Updated &&
for i in *
do
find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} ;
done
Why not parsels
(and what do to instead)?
– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
add a comment |
#!/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).
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 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 4 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 4 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 differentWorkarea
directories, and such details would be helpful.
– terdon♦
Jan 4 at 19:44
|
show 1 more comment
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492470%2fhow-to-replace-multiple-old-file-located-at-different-location-with-the-new-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this,
#!/bin/bash
cd /Updated &&
for i in *
do
find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} ;
done
Why not parsels
(and what do to instead)?
– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
add a comment |
Try this,
#!/bin/bash
cd /Updated &&
for i in *
do
find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} ;
done
Why not parsels
(and what do to instead)?
– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
add a comment |
Try this,
#!/bin/bash
cd /Updated &&
for i in *
do
find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} ;
done
Try this,
#!/bin/bash
cd /Updated &&
for i in *
do
find /Workarea -name "$i" -exec cp -f /Updated/"$i" {} ;
done
edited Jan 4 at 19:45
terdon♦
129k32253428
129k32253428
answered Jan 4 at 14:18
msp9011msp9011
3,82843863
3,82843863
Why not parsels
(and what do to instead)?
– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
add a comment |
Why not parsels
(and what do to instead)?
– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
Why not parse
ls
(and what do to instead)?– don_crissti
Jan 4 at 18:45
Why not parse
ls
(and what do to instead)?– don_crissti
Jan 4 at 18:45
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
Working fine. This solution replaces every file in /Workarea, including subdirectory, which matches with file in the /Updated directory. Is there any way to be more specific like /Updated/flower1.jpg should replace only the /Workarea/AssetGroupOne/flower1.jpg not the /Workarea/AssetGroupSix/flower1.jpg
– Shubham
Jan 7 at 6:49
add a comment |
#!/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).
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 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 4 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 4 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 differentWorkarea
directories, and such details would be helpful.
– terdon♦
Jan 4 at 19:44
|
show 1 more comment
#!/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).
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 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 4 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 4 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 differentWorkarea
directories, and such details would be helpful.
– terdon♦
Jan 4 at 19:44
|
show 1 more comment
#!/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).
#!/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).
answered Jan 4 at 13:56
nohillsidenohillside
2,382919
2,382919
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 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 4 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 4 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 differentWorkarea
directories, and such details would be helpful.
– terdon♦
Jan 4 at 19:44
|
show 1 more comment
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 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 4 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 4 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 differentWorkarea
directories, and such details would be helpful.
– terdon♦
Jan 4 at 19:44
I need to do this repeatedly for several files.
– Shubham
Jan 4 at 13:57
I need to do this repeatedly for several files.
– Shubham
Jan 4 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 4 at 14:11
@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 4 at 14:11
1
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 4 at 18:24
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 4 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 4 at 18:27
@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 4 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 4 at 19:44
@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 4 at 19:44
|
show 1 more comment
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492470%2fhow-to-replace-multiple-old-file-located-at-different-location-with-the-new-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes. Can you give an example of the file/directory names (from and to)?
– ctrl-alt-delor
Jan 4 at 13:12
Yes, I've updated my question.
– Shubham
Jan 4 at 13:56
Why do you want to use a script for this?
– nohillside
Jan 4 at 13:56
Are you sure about the directories starting with
/
? Aren't they located in your users home folder?– nohillside
Jan 4 at 13:59
So how can we know what the target of each file is? How can we know that
/Updated/flower1.jpg
should replace only/Workarea/AssetGroupOne/flower1.jpg
and not/Workarea/AssetGroupSix/flower1.jpg
? Can you create a text file with the file name and the target for each file?– terdon♦
Jan 7 at 9:01