How to copy multiple files and move them to multiple folders using terminal for Mac
I have a folder on my Mac's desktop called Bthepics that has 9 images that I want to copy and move to about 500 folders at once. These 500 folders are located in a folder on my Mac's desktop called bigcities. I don't want to have to do this manually by selecting all 9 images and dragging each group of nine to all 500 folders individually.
Can anybody show me how to do this using Mac's Terminal or Automator programs?
macos bash automator
add a comment |
I have a folder on my Mac's desktop called Bthepics that has 9 images that I want to copy and move to about 500 folders at once. These 500 folders are located in a folder on my Mac's desktop called bigcities. I don't want to have to do this manually by selecting all 9 images and dragging each group of nine to all 500 folders individually.
Can anybody show me how to do this using Mac's Terminal or Automator programs?
macos bash automator
The folderbigcitiescontains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?
– pabouk
Sep 16 '14 at 8:32
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39
add a comment |
I have a folder on my Mac's desktop called Bthepics that has 9 images that I want to copy and move to about 500 folders at once. These 500 folders are located in a folder on my Mac's desktop called bigcities. I don't want to have to do this manually by selecting all 9 images and dragging each group of nine to all 500 folders individually.
Can anybody show me how to do this using Mac's Terminal or Automator programs?
macos bash automator
I have a folder on my Mac's desktop called Bthepics that has 9 images that I want to copy and move to about 500 folders at once. These 500 folders are located in a folder on my Mac's desktop called bigcities. I don't want to have to do this manually by selecting all 9 images and dragging each group of nine to all 500 folders individually.
Can anybody show me how to do this using Mac's Terminal or Automator programs?
macos bash automator
macos bash automator
edited Sep 16 '14 at 8:31
pabouk
4,92953145
4,92953145
asked Sep 16 '14 at 8:18
MattMatt
111
111
The folderbigcitiescontains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?
– pabouk
Sep 16 '14 at 8:32
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39
add a comment |
The folderbigcitiescontains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?
– pabouk
Sep 16 '14 at 8:32
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39
The folder
bigcities contains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?– pabouk
Sep 16 '14 at 8:32
The folder
bigcities contains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?– pabouk
Sep 16 '14 at 8:32
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39
add a comment |
3 Answers
3
active
oldest
votes
This loops over every folder in bigcities, and copies all images from Bthepics to that folder.
Run this in Terminal, and see if it outputs what you want. You can simply copy-paste this block of code.
find ~/Desktop/bigcities -type d -maxdepth 1 -print0 | while IFS= read -r -d '' folder; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
To do the actual copying, remove the echo before pasting. I'm assuming that your source images have the extension .jpg.
Then just remove the original images manually.
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something likecp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove theechoand then paste it again, which will do the actual copying.
– slhck
Sep 16 '14 at 8:46
add a comment |
Here is a simpler code which does not need to run external command (find) and pipe the output. The rest is the same as in the slhck's reply.
cd ~/Desktop/bigcities ; for folder in */ ; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
This code has one drawback: The list of the destination folders must not exceed about 260 000 characters (command line size limit on Mac OS X 10.5). For 500 folders it is about 500 characters per folder name.
add a comment |
You should get familiar with xargs command for automation task like this:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/image[1-9].jpg %/
that was if your 9 images is named image1.jpg image2.jpg...
if your 9 images differ of names:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/file1.jpg ~/Desktop/Bthepics/file2.jpg ... ~/Desktop/Bthepics/file9.jpg %/
the command at the end of xargs is the same as you execute manually with % will be replaced by folders path
Btw, this command will copy images into the parent folder (~/Desktop/bigcities), so you need to remove it by 1 command:
rm ~/Desktop/bigcities/image[1-9].jpg
I hope you understand my idea and apply it for your case.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f812355%2fhow-to-copy-multiple-files-and-move-them-to-multiple-folders-using-terminal-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This loops over every folder in bigcities, and copies all images from Bthepics to that folder.
Run this in Terminal, and see if it outputs what you want. You can simply copy-paste this block of code.
find ~/Desktop/bigcities -type d -maxdepth 1 -print0 | while IFS= read -r -d '' folder; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
To do the actual copying, remove the echo before pasting. I'm assuming that your source images have the extension .jpg.
Then just remove the original images manually.
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something likecp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove theechoand then paste it again, which will do the actual copying.
– slhck
Sep 16 '14 at 8:46
add a comment |
This loops over every folder in bigcities, and copies all images from Bthepics to that folder.
Run this in Terminal, and see if it outputs what you want. You can simply copy-paste this block of code.
find ~/Desktop/bigcities -type d -maxdepth 1 -print0 | while IFS= read -r -d '' folder; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
To do the actual copying, remove the echo before pasting. I'm assuming that your source images have the extension .jpg.
Then just remove the original images manually.
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something likecp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove theechoand then paste it again, which will do the actual copying.
– slhck
Sep 16 '14 at 8:46
add a comment |
This loops over every folder in bigcities, and copies all images from Bthepics to that folder.
Run this in Terminal, and see if it outputs what you want. You can simply copy-paste this block of code.
find ~/Desktop/bigcities -type d -maxdepth 1 -print0 | while IFS= read -r -d '' folder; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
To do the actual copying, remove the echo before pasting. I'm assuming that your source images have the extension .jpg.
Then just remove the original images manually.
This loops over every folder in bigcities, and copies all images from Bthepics to that folder.
Run this in Terminal, and see if it outputs what you want. You can simply copy-paste this block of code.
find ~/Desktop/bigcities -type d -maxdepth 1 -print0 | while IFS= read -r -d '' folder; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
To do the actual copying, remove the echo before pasting. I'm assuming that your source images have the extension .jpg.
Then just remove the original images manually.
edited Sep 16 '14 at 8:47
answered Sep 16 '14 at 8:23
slhckslhck
160k47445467
160k47445467
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something likecp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove theechoand then paste it again, which will do the actual copying.
– slhck
Sep 16 '14 at 8:46
add a comment |
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something likecp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove theechoand then paste it again, which will do the actual copying.
– slhck
Sep 16 '14 at 8:46
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
Hi slhck! Thanks for the fast reply! I'm very new to coding, do I need to actually type in "find" and "done" in the code? Meaning can I just copy and paste the code you gave me as is into Terminal?
– Matt
Sep 16 '14 at 8:38
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something like
cp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove the echo and then paste it again, which will do the actual copying.– slhck
Sep 16 '14 at 8:46
You just take the entire block of code and copy-paste it to the terminal. It should output 500 lines, something like
cp IMAGE_1.jpg IMAGE_2.jpg ... IMAGE_9.jpg /Users/matt/Desktop/bigcities/FOLDER_1/, for you to inspect that it's doing the right thing. Once you're sure, you need to remove the echo and then paste it again, which will do the actual copying.– slhck
Sep 16 '14 at 8:46
add a comment |
Here is a simpler code which does not need to run external command (find) and pipe the output. The rest is the same as in the slhck's reply.
cd ~/Desktop/bigcities ; for folder in */ ; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
This code has one drawback: The list of the destination folders must not exceed about 260 000 characters (command line size limit on Mac OS X 10.5). For 500 folders it is about 500 characters per folder name.
add a comment |
Here is a simpler code which does not need to run external command (find) and pipe the output. The rest is the same as in the slhck's reply.
cd ~/Desktop/bigcities ; for folder in */ ; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
This code has one drawback: The list of the destination folders must not exceed about 260 000 characters (command line size limit on Mac OS X 10.5). For 500 folders it is about 500 characters per folder name.
add a comment |
Here is a simpler code which does not need to run external command (find) and pipe the output. The rest is the same as in the slhck's reply.
cd ~/Desktop/bigcities ; for folder in */ ; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
This code has one drawback: The list of the destination folders must not exceed about 260 000 characters (command line size limit on Mac OS X 10.5). For 500 folders it is about 500 characters per folder name.
Here is a simpler code which does not need to run external command (find) and pipe the output. The rest is the same as in the slhck's reply.
cd ~/Desktop/bigcities ; for folder in */ ; do
echo cp ~/Desktop/Bthepics/*.jpg "$folder"
done
This code has one drawback: The list of the destination folders must not exceed about 260 000 characters (command line size limit on Mac OS X 10.5). For 500 folders it is about 500 characters per folder name.
edited Sep 16 '14 at 9:12
answered Sep 16 '14 at 8:47
paboukpabouk
4,92953145
4,92953145
add a comment |
add a comment |
You should get familiar with xargs command for automation task like this:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/image[1-9].jpg %/
that was if your 9 images is named image1.jpg image2.jpg...
if your 9 images differ of names:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/file1.jpg ~/Desktop/Bthepics/file2.jpg ... ~/Desktop/Bthepics/file9.jpg %/
the command at the end of xargs is the same as you execute manually with % will be replaced by folders path
Btw, this command will copy images into the parent folder (~/Desktop/bigcities), so you need to remove it by 1 command:
rm ~/Desktop/bigcities/image[1-9].jpg
I hope you understand my idea and apply it for your case.
add a comment |
You should get familiar with xargs command for automation task like this:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/image[1-9].jpg %/
that was if your 9 images is named image1.jpg image2.jpg...
if your 9 images differ of names:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/file1.jpg ~/Desktop/Bthepics/file2.jpg ... ~/Desktop/Bthepics/file9.jpg %/
the command at the end of xargs is the same as you execute manually with % will be replaced by folders path
Btw, this command will copy images into the parent folder (~/Desktop/bigcities), so you need to remove it by 1 command:
rm ~/Desktop/bigcities/image[1-9].jpg
I hope you understand my idea and apply it for your case.
add a comment |
You should get familiar with xargs command for automation task like this:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/image[1-9].jpg %/
that was if your 9 images is named image1.jpg image2.jpg...
if your 9 images differ of names:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/file1.jpg ~/Desktop/Bthepics/file2.jpg ... ~/Desktop/Bthepics/file9.jpg %/
the command at the end of xargs is the same as you execute manually with % will be replaced by folders path
Btw, this command will copy images into the parent folder (~/Desktop/bigcities), so you need to remove it by 1 command:
rm ~/Desktop/bigcities/image[1-9].jpg
I hope you understand my idea and apply it for your case.
You should get familiar with xargs command for automation task like this:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/image[1-9].jpg %/
that was if your 9 images is named image1.jpg image2.jpg...
if your 9 images differ of names:
find ~/Desktop/bigcities -type d -print0 | xargs -I% cp ~/Desktop/Bthepics/file1.jpg ~/Desktop/Bthepics/file2.jpg ... ~/Desktop/Bthepics/file9.jpg %/
the command at the end of xargs is the same as you execute manually with % will be replaced by folders path
Btw, this command will copy images into the parent folder (~/Desktop/bigcities), so you need to remove it by 1 command:
rm ~/Desktop/bigcities/image[1-9].jpg
I hope you understand my idea and apply it for your case.
answered Sep 16 '14 at 10:55
incousincous
462
462
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f812355%2fhow-to-copy-multiple-files-and-move-them-to-multiple-folders-using-terminal-for%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
The folder
bigcitiescontains only those 500 destination folders and nothing else? ... or is there a different way how to identify those 500 destination folders?– pabouk
Sep 16 '14 at 8:32
Hi @pabouk, the folder <code>bigcities</code> only contains the destination folders.
– Matt
Sep 16 '14 at 8:39