4

I want to place 1 file called "test1.html" in 100 different directories of website.

Directory structure is like the following

/home/domain.com/public_html/ (domain.com name are change for every directory so i use * .

File are here: /root/test1.html

I have try it by : cp test1.html /home/*/public_html/ via root account but give me

cp: omitting directory `/home/domain1.com/public_html/'
cp: omitting directory `/home/domain2.com/public_html/'

and so on.

how to place the one file in all domains directory?

it's Centos 5.9

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2986500
  • 53
  • 1
  • 1
  • 6

3 Answers3

3

Try:

for dest in /home/*/public_html/
do 
   cp test1.html $dest
done

Since you are writing in user-owned directories be careful of you umask setting - it controls permissions on the file. You can use cp -p to keep the exact permissions on test1.html preserved.

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51
0

Try this:

cd /home/; find . -name public_html -type d | xargs -I {} cp /root/test1.html {};
Harry
  • 1,362
  • 12
  • 19
  • Thanks but not working. [root@uk ~]# cd /home/; find . -name public_html -type d | xargs -i {} cp /root/googleba3771cddb278c04.html {}; xargs: {}: No such file or directory – user2986500 Nov 21 '13 at 13:27
  • Damn. Its capital i: Edited response – Harry Nov 21 '13 at 13:35
-1

It should be written: cp -R test1.html /home/*/public_html/

-R stands for recursive and without it it doesn't want to do all the directories.