simple copy question
Ok, why when I type cp /home/trial/USER.MAN /home/*/ does it reply: omitting /home/trial2 omitting /home/trial3 I want to copy the files to all directories under home. I'm overlooking something stupid I'm sure. Thanks in advance -- Matt Johnson ____________________________________________________________ Do You Yahoo!? Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk or your free @yahoo.ie address at http://mail.yahoo.ie
On Thu, Sep 13, 2001 at 09:13:48PM +0100, Matt Johnson wrote:
Ok, why when I type
cp /home/trial/USER.MAN /home/*/
does it reply:
omitting /home/trial2 omitting /home/trial3
errr... I don't know.
I want to copy the files to all directories under home.
Try: # find /home -type d -maxdepth 1 -regex '/home/.*' -exec cp /home/trial/USER.MAN {}/ \; If you want to copy the file to *all* directories under /home (and I don't think you do!) then omit the maxdepth option. It's always worth testing first without the -exec option to make sure that find finds the directories you're interested in before commitimg yourself - especially if you're using rm as an argument to -exec ;-) Powerful tool `find' & one worth learning for all sorts of file management purposes eg. backups, creating tarballs. Good manpage and also info page for some examples. -- Frank *-*-*-*-*-*-*-*-*-*-* Boroughbridge. Tel: 01423 323019 --------- PGP keyID: 0xC0B341A3 *-*-*-*-*-*-*-*-*-*-* http://www.esperance-linux.co.uk/
On Fri, Sep 14, 2001 at 04:32:42AM +0100, Frank Shute wrote:
On Thu, Sep 13, 2001 at 09:13:48PM +0100, Matt Johnson wrote:
Ok, why when I type
cp /home/trial/USER.MAN /home/*/
does it reply:
omitting /home/trial2 omitting /home/trial3
errr... I don't know.
I want to copy the files to all directories under home.
Try:
# find /home -type d -maxdepth 1 -regex '/home/.*' -exec cp /home/trial/USER.MAN {}/ \;
Sorry, misread the question & thought you were just copying a single file rather than a dir. cp -R is the way to go as Derek suggests. You can still use find though (new improved version coming up!): # find /home -type d -mindepth 1 -maxdepth 1 -regex '/home/.*' \ -path '/home/trial' -prune -o -print -exec cp -R /home/trial/USER.MAN {} \; I think... If you use: cp -R /home/trial/USER.MAN /home/*/ then you might have problems when it tries to copy on itself as the glob will pick up /home/trial BTW, having a guess that USER.MAN might contain documentation for users, then it might be best to make a dir that's readable but not writable by all and stick the stuff in there - possibly under /usr/doc -- Frank *-*-*-*-*-*-*-*-*-*-* Boroughbridge. Tel: 01423 323019 --------- PGP keyID: 0xC0B341A3 *-*-*-*-*-*-*-*-*-*-* http://www.esperance-linux.co.uk/
Thanks all - I'll try tose suggestions. I will use the echo command to see how things expand. Great stuff. Ta -- Matt ____________________________________________________________ Do You Yahoo!? Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk or your free @yahoo.ie address at http://mail.yahoo.ie
On Thursday 13 September 2001 21:13 hrs, you wrote:
Ok, why when I type
cp /home/trial/USER.MAN /home/*/
does it reply:
omitting /home/trial2 omitting /home/trial3
I want to copy the files to all directories under home.
Not stupid! Don't forget that cp -h will list the options for you. You need to use -R to copy directories recursively. -r is a less powerful recursion feature which only handles directories. Non-directory references are always copied as files so FIFOs etc don't copy correctly. -- Best wishes, Derek Harding, (BA MIAP) ICT & Network Manager hardingd@warlingham.surrey.sch.uk
On Fri, 14 Sep 2001, Derek Harding wrote:
Ok, why when I type cp /home/trial/USER.MAN /home/*/ does it reply: omitting /home/trial2 omitting /home/trial3 I want to copy the files to all directories under home. Not stupid! Don't forget that cp -h will list the options for you. You need to use -R to copy directories recursively.
This is irrelevant. You need to think for a few seconds about how Unix command expansion works. Suppose /home contained three folders, trial, trial2 and trial3. Then /home/*/ would expand to /home/trial/ /home/trial2/ /home/trial3/ You can verify this by typing "echo /home/*/" Now consider how the command "cp /home/trial/USER.MAN /home/*/" would expand: cp /home/trial/USER.MAN /home/trial/ /home/trial2/ /home/trial3/ As with most operating systems' copy commands, cp assumes that arguments are of the general form cp SOURCE1 SOURCE2 SOURCE3 ... SOURCEN DEST Thus the command is clearly not going to achieve the desired result! Something like for i in /home/*/; do cp /home/trial/USER.MAN $i; done would do the trick as long as none of the folders in /home have spaces in their names. Incidentally, this is related to a well-known gaffe of Unix sysadmins. Suppose you want to remove all hidden files and folders (i.e. those beginning with a .) in a particular directory. The "obvious" command would be something like rm -rf .* However, a quick "echo .*" will show that it expands to include both "." (i.e. the whole current directory) and ".." (i.e. the parent directory). A quick recipe for wiping large parts of your file system! HTH, Michael Brown Fen Systems Ltd. -- http://www.fensystems.co.uk/
participants (4)
-
Derek Harding
-
Frank Shute
-
Matt Johnson
-
Michael Brown