LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
LinkBack Search this Thread
Old 11-15-2005, 07:41 AM   #1
plisken
Member
 
Registered: Dec 2001
Location: Scotland
Distribution: Slackware 9.1/11/13.37 RedHat 6.2/7 SuSE 8.2/11.1
Posts: 319

Rep: Reputation: 30
copy problem using wildcards


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.

The error shows:

cp: omitting directory `/var/www/www.domain1.com/public_html/'
cp: omitting directory `/var/www/www.domain2.comk/public_html/'
cp: omitting directory `/var/www/www.othersite.comk/public_html/'
cp: omitting directory `/var/www/www.yetanothersite.com/public_html/'


Thanks in advance...
 
Old 11-15-2005, 08:10 AM   #2
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717

Rep: Reputation: 33
There is no problem, copy will ignore directory when it is stated using wildcards.
 
Old 11-15-2005, 08:17 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 53
Might be just as easy to loop through it...
Code:
for i in `ls /var/www` ; do cp file.txt /var/www/$i ; done

Last edited by homey; 11-15-2005 at 08:21 AM.
 
Old 11-15-2005, 08:18 AM   #4
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717

Rep: Reputation: 33
If you want to use that command, add the -r options behind cp
 
Old 11-15-2005, 08:36 AM   #5
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
yeah -r for recursive, will conduct the operation to folders in msot commands, cp, rm,
 
Old 11-15-2005, 09:05 AM   #6
plisken
Member
 
Registered: Dec 2001
Location: Scotland
Distribution: Slackware 9.1/11/13.37 RedHat 6.2/7 SuSE 8.2/11.1
Posts: 319

Original Poster
Rep: Reputation: 30
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...

Last edited by plisken; 11-15-2005 at 09:10 AM.
 
Old 11-15-2005, 09:21 AM   #7
plisken
Member
 
Registered: Dec 2001
Location: Scotland
Distribution: Slackware 9.1/11/13.37 RedHat 6.2/7 SuSE 8.2/11.1
Posts: 319

Original Poster
Rep: Reputation: 30
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.

cp -r hello.* www.*/ This produces the following:

www.1 is empty
www.2 is empty
www.3 contains hello.c, hello.o www.1 and www.2
 
Old 11-15-2005, 10:21 AM   #8
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717

Rep: Reputation: 33
Eureka! I found it

From the line which Homey posted, I enhanced it and make a shell script which have worked for your later example.
Code:
Locate=""
abc=""
for Locate in ls -d ./www*
do 
	for abc in ./hello*
	do cp ./$abc ./$Locate
	done
done
Try it out!
It may be so clumsy because this is the first time I wrote a shell script.
So, forgive me if it don't work

Last edited by TruongAn; 11-15-2005 at 10:25 AM.
 
Old 11-16-2005, 01:08 AM   #9
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717

Rep: Reputation: 33
Did my script work?
This is the first time I write a script so I need comments, please post back, PLEASE

Last edited by TruongAn; 11-16-2005 at 01:10 AM.
 
Old 11-16-2005, 03:47 AM   #10
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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.

Last edited by BrianK; 11-16-2005 at 03:49 AM.
 
Old 11-16-2005, 04:35 AM   #11
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 46
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.
 
Old 11-16-2005, 08:34 AM   #12
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 717

Rep: Reputation: 33
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

Last edited by TruongAn; 11-16-2005 at 09:16 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of wildcards and -R switch in ls and grep robgee1964 Linux - Newbie 7 12-04-2005 05:20 PM
Handling wildcards... artificialGekko Linux - General 5 03-24-2005 08:29 PM
CLI wildcards ShakyJake Linux - Newbie 4 02-28-2005 03:42 PM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 05:33 AM
Wildcards in kernel Squall Linux - General 1 04-20-2004 05:22 PM


All times are GMT -5. The time now is 11:06 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration