2

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!

2 Answers 2

1

Hi here is a script you can use:

#!/bin/sh

DIR_TO_COPY="400K"

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

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

chmod 755 toto.sh

to run it:

./toto.sh 500K 600K 700K

0

Use xargs:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .