Copying the same file to multiple directories

Ask a Question related to SCO, Design and Development.

  1. #1

    Default Copying the same file to multiple directories

    .... say I wanted to copy a file, call it "welcome", to every user's home
    directory. I know that all the folders live in /usr; thus /usr/first,
    /usr/second, ... /usr/thousand-and-twenty-two, ...

    IOW, I want to automate:

    $ cd /usr
    $ cp /path-to-welcome first
    $ cp /path-to-welcome second
    $ cp /path-to-welcome third
    $ cp /path-to-welcome fourth

    etc.

    What's the nicest/easiest way to do this? SCO 506.

    Thanks!

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacs@egps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  2. Similar Questions and Discussions

    1. Maintaining multiple Web Server Route Directories
      Is there a way to create a root (home) directory for multiple websites on the same machine (with IIS)? For instance, I would like to use this...
    2. Multiple directories
      I'm wondering if I can set up a client to update her own site using Contribute. The site is for a quarterly magazine. Updates include creating new...
    3. Using virtual directories for common directories (scripts, images, styles, etc.)
      Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of...
    4. How can I get multiple directories using ftp?
      Any idea, what is the right command, in my earlier posting somebody suggested to use mget *, but that is not working. Thanks in advance.
    5. What directories can be shared between multiple distributions on the same machine??
      If I want to install multiple distributions on one machine, there should be some parts that can be shared, such as SWAP, /tmp(if u made it a...
  3. #2

    Default Re: Copying the same file to multiple directories

    Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    > ... say I wanted to copy a file, call it "welcome", to every user's home
    > directory. I know that all the folders live in /usr; thus /usr/first,
    > /usr/second, ... /usr/thousand-and-twenty-two, ...
    >
    > IOW, I want to automate:
    >
    > $ cd /usr
    > $ cp /path-to-welcome first
    > $ cp /path-to-welcome second
    > $ cp /path-to-welcome third
    > $ cp /path-to-welcome fourth
    >
    > etc.
    >
    > What's the nicest/easiest way to do this? SCO 506.
    >
    > Thanks!
    Following up my own post, I tried:

    $ for F in *
    do
    copy /path-to-welcome $F
    done

    which worked somewhat, except:

    a) It destroyed two (of ten or so) .docs, rendering them zero bytes.

    b) It didn't copy to directories with spaces in them, giving errors:

    cp: target (Enterprises) must be a directory
    Usage: cp [-fip] source_file target_file
    cp [-r|-R][-fip] source_file... target_file

    Thanks, again.

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacs@egps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  4. #3

    Default Re: Copying the same file to multiple directories

    Nachman Yaakov Ziskind typed (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    | ... say I wanted to copy a file, call it "welcome", to every user's home
    | directory. I know that all the folders live in /usr; thus /usr/first,
    | /usr/second, ... /usr/thousand-and-twenty-two, ...
    |
    | IOW, I want to automate:
    |
    | $ cd /usr
    | $ cp /path-to-welcome first
    | $ cp /path-to-welcome second
    | $ cp /path-to-welcome third
    | $ cp /path-to-welcome fourth
    |
    | etc.
    |
    | What's the nicest/easiest way to do this? SCO 506.


    #!/bin/ksh
    for D in `awk -F: '$3 >= 200 { print $6 }' /etc/passwd`
    do
    [[ -f $D/.profile || -f $D/.login ]] && cp /path-to-welcome $D
    done

    Slight aside: 5.0.7 does not place users in /usr by default, but in /u.
    Take the trouble to move them all there now, it will make your eventual
    upgrade far less annoying. The script I just wrote gives you the bare
    bones for another script to both edit /etc/passwd and move the home
    directories.

    --
    JP
    Jean-Pierre Radley Guest

  5. #4

    Default Re: Copying the same file to multiple directories

    > Nachman Yaakov Ziskind wrote (on Tue, Jul 01, 2003 at 04:34:13PM +0000):
    > > ... say I wanted to copy a file, call it "welcome", to every user's home
    > > directory. I know that all the folders live in /usr; thus /usr/first,
    > > /usr/second, ... /usr/thousand-and-twenty-two, ...
    > >
    > > IOW, I want to automate:
    > >
    > > $ cd /usr
    > > $ cp /path-to-welcome first
    > > $ cp /path-to-welcome second
    > > $ cp /path-to-welcome third
    > > $ cp /path-to-welcome fourth
    > >
    > > etc.
    > >
    > > What's the nicest/easiest way to do this? SCO 506.
    > >
    > > Thanks!
    >
    > Following up my own post, I tried:
    >
    > $ for F in *
    > do
    > copy /path-to-welcome $F
    > done
    >
    > which worked somewhat, except:
    >
    > a) It destroyed two (of ten or so) .docs, rendering them zero bytes.
    I am assuming that your copy overlayed some existing doc's in the parent
    directory. I realize I am stating the obvious but just wanted to clarify.
    Here is a script that would at least eliminate that problem.

    $for F in *
    do
    if [ -d $F ]; then
    cp /path-to-welcome "$F"
    fi
    done

    I ran a limited test and it appeared to work. I hope this helps as this is
    about the extent of my shell programming knowledge.

    justin



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.495 / Virus Database: 294 - Release Date: 6/30/03


    justin Guest

  6. #5

    Default Re: Copying the same file to multiple directories

    In article <bdsrl6$qoe$1@news.tdl.com>,
    justin <justin_robbs@NO_SPAMhotmail.com> wrote:
    >$for F in *
    >do
    > if [ -d $F ]; then
    > cp /path-to-welcome "$F"
    > fi
    >done
    Close, but to avoid problems with filenames that include whitespace, you also
    need to quote $F inside of [] (note that this is not true in ksh's [[]] ).

    John
    --
    John DuBois [email]spcecdt@armory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
    John DuBois Guest

  7. #6

    Default Re: Copying the same file to multiple directories

    John DuBois wrote (on Wed, Jul 02, 2003 at 12:45:25AM +0000):
    > In article <bdsrl6$qoe$1@news.tdl.com>,
    > justin <justin_robbs@NO_SPAMhotmail.com> wrote:
    > >$for F in *
    > >do
    > > if [ -d $F ]; then
    > > cp /path-to-welcome "$F"
    > > fi
    > >done
    >
    > Close, but to avoid problems with filenames that include whitespace, you also
    > need to quote $F inside of [] (note that this is not true in ksh's [[]] ).
    >
    > John
    Thanks to both Justin and John for replying. I tried Justin's suggestion; it
    worked on the directory names without spaces, as well as *some of* the ones
    with spaces (have no clue why). Note that I was using ksh.

    Then I tried replacing the first $F with sh:

    if [ -d "$F" ]; then

    And it worked. Woo-hoo!

    Time to sacrifice a virgin by the altar of Unix.

    NYZ

    --
    _________________________________________
    Nachman Yaakov Ziskind, EA, LLM [email]awacs@egps.com[/email]
    Attorney and Counselor-at-Law [url]http://yankel.com[/url]
    Economic Group Pension Services [url]http://egps.com[/url]
    Actuaries and Employee Benefit Consultants
    Nachman Yaakov Ziskind Guest

  8. #7

    Default Re: Copying the same file to multiple directories

    Bill Vermillion <bv@wjv.comremove> wrote:
    >To my way of thinking about it the easiest way is NOT to copy
    >the file to all those user files - particularly if you do
    >have 1022 or more users as the folders indicate.

    Exactly my immediate first thought.
    >1022 files of only 20 bytes [for an exmaple] will occupy a minimum
    >of 1MB - as each file takes two disk blocks.
    >If these are typical welcome messages then the user never needs to
    >modify them, or even has permission to do so.
    >I'd opt for a link to the files - not symbolic but a hard link.
    But why even do that? I'm assuming (and that may be the problem) that
    some program somewhere displays the file. Why not just point that program
    at one place?

    --
    [email]tony@aplawrence.com[/email] Unix/Linux resources: [url]http://aplawrence.com[/url]
    Inexpensive phone/email support
    Free SCO Skills Test: [url]http://pcunix.com/skilltests.html[/url]
    tony@aplawrence.com Guest

  9. #8

    Default Re: Copying the same file to multiple directories

    In article <20030701233715.A986@egps.egps.com>,
    Nachman Yaakov Ziskind <awacs@egps.com> wrote:
    >John DuBois wrote (on Wed, Jul 02, 2003 at 12:45:25AM +0000):
    >> Close, but to avoid problems with filenames that include whitespace, you also
    >> need to quote $F inside of [] (note that this is not true in ksh's [[]] ).
    >
    >Thanks to both Justin and John for replying. I tried Justin's suggestion; it
    >worked on the directory names without spaces, as well as *some of* the ones
    >with spaces (have no clue why). Note that I was using ksh.
    Sorry, I don't think I was clear: you don't need to quote variables to avoid
    field splitting and globbing inside of ksh's [[ ]] operators, which are
    alternatives to the [ ] that exist in both sh and sh. In ksh you can do:

    if [[ -d $F ]]; then ...

    while even in ksh you do need to do:

    if [ -d "$F" ]; then ...

    This is because [ in ksh is emulating an external program called '[', and so
    field splitting and globbing must be performed as they are for all other
    external programs. [[ ]] are new, explicitly built-in keywords that have new
    behavior defined for them. For non-arithmetic operations, I use them in
    preference to [] in ksh programs; in addition to avoiding the need for quoting
    in the above cases, they allow for pattern matching, more sensible boolean
    expressions, etc. For arithmetic operations, I use (()), which allow for most
    C expressions and then some.

    John
    --
    John DuBois [email]spcecdt@armory.com[/email] KC6QKZ/AE [url]http://www.armory.com/~spcecdt/[/url]
    John DuBois Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139