Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm come accross a strange problem, well at least I think its strange.
I'm trying to copy a file to a location as follows:
cp FILE /var/www/www.*/public_html/
Now I am in the current dir and the file FILE exists, as do several folders www.domain1.com,www.domains2.com etc, all within /var/www/
Yet this does not work, any ideas?
Obviously, I vcan and did as it happens copy the file to each folder manualy, but thought it would have been nice to do it using the method above.
using -r in this instance produces really bad results, it strated to copy everything from one www.*/public_html folder to another www.*/public_html folder and seemed to want to go forever...
or perhaps it didn't, though it did take ages and using the -v switch, certainly went through every file within the www.*/public/html dir and beyond...
This simply does not work, take this example and then comment or advise please is someone can:
Working in CURRENT dir, create the following folders, www.1,www.2,www.3
We have two files in the CURRENT working dir, named hello.c and hello.o.
Now if I wanted to copy bothe the hello files into the 3 newly created sub dirs, then I would expec to do the following:
cp hello.* www.*/ Tthis don't work as mentioned in my 1st post, so i have tried the following:
cp hello.* www.* This is basically the same as above in this instance.
I don't think you guys are doing the script correctly... he needs to do this:
cp FILE /var/www/www.*/public_html/
in tcsh:
Code:
foreach f (/var/www/www.*)
echo $f # shows progress
cp FILE $f/public_html # don't forget the public_html bit
end
the bash version would be the same as homey's post, but don't forget the public_html following the $i
btw: cp does not copy to multiple destinations by design. Wildcards are for sources, there is always only one destination - this is true for most file commands.
Yes, wildcards don't work because they get expanded by the shell into separate arguments. So the OP's command will get expanded to this (let's say the wildcards stood for numbers 1 to 3):
cp FILE /var/www/www.1/public_html/ /var/www/www.2/public_html/ /var/www/www.3/public_html/
And then by design cp will try to copy the three things "FILE", "/var/www/www.1/public_html/", and "/var/www/www.2/public_html/" into the last thing "/var/www/www.3/public_html/"!
If you guys want to copy multiple files by wildcards or something, the "mmv" program might be useful.
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717
Rep:
Quote:
Originally posted by BrianK I don't think you guys are doing the script correctly... he needs to do this:
cp FILE /var/www/www.*/public_html/
in tcsh:
Code:
foreach f (/var/www/www.*)
echo $f # shows progress
cp FILE $f/public_html # don't forget the public_html bit
end
the bash version would be the same as homey's post, but don't forget the public_html following the $i
I have tried homey's line but I didn't work.
I tried it with the second example post by plisken
Code:
Working in CURRENT dir, create the following folders, www.1,www.2,www.3
We have two files in the CURRENT working dir, named hello.c and hello.o.
Now if I wanted to copy bothe the hello files into the 3 newly created sub dirs, then I would expec to do the following:
It just copy the file to www.3 dir and ommit other dir
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.