If I have thousands of folders named a/ b/ c/
etc, how can I duplicate them and their contents multiple times such that the copied folder would be given a different name eg a-copy1/ b-copy1/ c-copy1/ ... a-copy12/ b-copy12/ c-copy12/
If I have thousands of folders named a/ b/ c/
etc, how can I duplicate them and their contents multiple times such that the copied folder would be given a different name eg a-copy1/ b-copy1/ c-copy1/ ... a-copy12/ b-copy12/ c-copy12/
This script should make that possible:
Information:
for r in $(seq 1 5)
: This allows you to pick the number of copies to create.if [ -d "$i" ]
: check if the target is a folder.cp -r "$i" "$i"\-copy"$r"
: perform the copy.set -e
: stop on first error.Sample data:
Sample output:
If you have "thousands" of files and/or directories to process,
find
andxargs
are the tools of choice. Readman find
andman xargs
.Where
bash_script
is a file (mode 755), in your$PATH
containing a user-written script to do the copying.Try in your directory:
You will get all folders with the "pattern" get duplicate and rename with -copy1 at the end.
You may write a simple bash script like:
This snippet will make 10 copies of the directories located on /src/dir to /dst/dir