I have a directory called 400K that has some files in it, I want to copy this directory multiple times but with different names. I want something like: cp -r 400K 500K 600K 700K

I was considering using a for loop and run a shell script, but I don't know how to start!


Hi here is a script you can use:



for var in "$@"
      echo "Copying $DIR_TO_COPY to $var ..."
      cp -rf $DIR_TO_COPY $var

let's name it toto.sh and don't forget to run:

chmod 755 toto.sh

to run it:

./toto.sh 500K 600K 700K


Use xargs:

echo 500K 600K 700K| xargs -n1 cp -r 400K

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.