karlosuccess
karlosuccess

Reputation: 885

Unix command CP to copy a file to multiple directories

I have folder structure like this:

/home/
   /folder1/
      /backup/
   /folder2/
      /backup/
   /folder3/
   /folder4/
      /backup/
   /folder5/

(As you can see, no all directories "folder" have a directory "backup")

I need to copy the script "checker.php" to all "backup" directories only.

"checker.php" is at:

/home/checker.php

I am using this command:

cp /home/checker.php /home/*/backup/checker.php

But it is not working. What can I try next?

Upvotes: 0

Views: 689

Answers (1)

oliv
oliv

Reputation: 13249

The cp command doesn't allow multiple destination directories.

A way forward is to loop through the folders:

for d in /home/*/backup; do 
    cp /home/checker.php "$d"
done

Upvotes: 2

Related Questions