Find the answer to your Linux question:
Results 1 to 4 of 4
Is there an easy way to copy a single file into multiple subdirectories? I have a situation where about 80 sub-dirs contain a file that needs to be updated with ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003
    Posts
    2

    File Mgmnt


    Is there an easy way to copy a single file into multiple subdirectories? I have a situation where about 80 sub-dirs contain a file that needs to be updated with a new version. Doing this by hand would be tedious at best. =\ I know I know, prolly shoulda been a symlink to a main file in the first place, but it isn't.. heh Alternatively, would there be an easy way to change all of the files in the sub dirs into symlinks without going into each subdir and doing it by hand?

    Or.. ?
    Suggestions?

    Thanks in advance

  2. #2
    Just Joined!
    Join Date
    Nov 2002
    Location
    USA
    Posts
    99
    Write a shell script to do the job.

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Why, of course! This is UNIX we're talking about.
    First, you need to construct a list of the directories. Since I don't know the actual directory structure, I'm going to assume for this demo that they are all in the same directory, and called subdir-0 to subdir-79. The master file is in the parent dir and is called "master". The files to be updated will be called oldcopy. If that would be the case, just execute this (being in the parent directory):
    Code:
    for dir in subdir-*; do rm $dir/oldcopy; ln -s ../master $dir/oldcopy; done
    It isn't harder than that.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Apr 2003
    Posts
    2
    Quote Originally Posted by Dolda2000
    Why, of course! This is UNIX we're talking about.
    First, you need to construct a list of the directories. Since I don't know the actual directory structure, I'm going to assume for this demo that they are all in the same directory, and called subdir-0 to subdir-79. The master file is in the parent dir and is called "master". The files to be updated will be called oldcopy. If that would be the case, just execute this (being in the parent directory):
    Code:
    for dir in subdir-*; do rm $dir/oldcopy; ln -s ../master $dir/oldcopy; done
    It isn't harder than that.
    Thank you so much!

    That was too easy...

Posting Permissions

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