How can I copy a number of directories:


to different directories


where each tmp_directory_* directory has the same content(files and subdirectories) as directory_*. For example tmp_directory_01 will have the same contents as directory_01.

  • You want to copy only the contents of directory_x to tmp_directory_x or you want to have directory_x as subdirectory of tmp_directory_x ? – Sergiy Kolodyazhnyy Jul 3 '15 at 18:14
  • @Serg The first one. – Sebi Jul 3 '15 at 18:15
  • @Sebi then you may want to go with drewbenn's method , except I'd change the code to cp -R "$d"/* "tmp_$d" – Sergiy Kolodyazhnyy Jul 3 '15 at 18:19
  • 1
    @drewbenn post it as an answer – Sergiy Kolodyazhnyy Jul 3 '15 at 18:19
  • @serg, Did you test your code. I can not see how it can work. – ctrl-alt-delor Jul 3 '15 at 18:23

Posting comment as answer:

for d in directory_*; do cp -R "$d" "tmp_$d"; done

Credits @drewbenn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.