Updating a library file to multiple locations in Linux

49 views Asked by At

I've got a library file that I often access, as you would, from the library. eg /library/component.js But sometimes that needs to be accessed as a copy in a project folder. eg. .../someProject/library/component.js

My problem is that if I update the master version of component.js I want the many project versions updated also. I don't know where all the project copies are except they do have one root directory which for this discussion let's call /projects.

The algorithm is:

(1) Search for component.js in all sub-dirs of /projects.

(2) Update with master file if newer

(Other build and update functions such as FTP are outside the scope, but a log would be nice.)

Q1: Is there a Linux utility that will snap into action?

Q2: Can anyone suggest a shell script?

(I can do clever MS-DOS batch scripts but I'm a novice when it comes to the Linux command line.)

2

There are 2 answers

0
AudioBubble On

If the files you are trying to update, are not created and deleted frequently, you can use locate command.

(1) Search for component.js in all sub-dirs of /projects. (Use locate component.js)

Then you may make use of rsync to update those files one by one. Maybe by traversing the output of the locate command.

p.s.

If you couldn't locate your files, just run "updatedb" command once.

1
Armali On

(1) Search for component.js in all sub-dirs of /projects.

(2) Update with master file if newer

(Other build and update functions such as FTP are outside the scope, but a log would be nice.)

Q1: Is there a Linux utility that will snap into action?

Yes, it's called find:

find /projects -name component.js ! -newer /library/component.js -exec cp /library/component.js {} \;

For a log we can add the option -v after cp and redirect the output.