0

How can I copy a number of directories:

directory_01
directory_02
directory_03

to different directories

tmp_directory_01
tmp_directory_02
tmp_directory_03

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.

  • 3
    for d in directory_*; do cp -R "$d" "tmp_$d"; done – drewbenn Jul 3 '15 at 18:13
  • 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
1

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.