LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ask-how to update files with the same name (https://www.linuxquestions.org/questions/linux-newbie-8/ask-how-to-update-files-with-the-same-name-4175506422/)

aaronuq 05-29-2014 03:50 PM

ask-how to update files with the same name
 
Hi guys,

I have many small codes which have been used in many different folders. And those codes will get updated at times, so I wondering how can I update them in different folders at the same time instead of going into each folder to check whether there is any code that needs to be updated.

I am thinking that at first I can find all the paths that contain the to-be-updated-codes, and them copy the new codes to those folders. But I don't know how to do this with linux commands, and any better suggestions?

Thank you!

Aaron.

evo2 05-29-2014 09:14 PM

Hi,

not completely sure what you are actually asking, but the command rsync can be used to only copy files if the source file is newer (and different) to the destination file. Eg

Code:

rsync -auv /path/to/source/ /path/to/destination/
will recursively copy files in /path/to/source/ into /path/to/destination/ if the files are missing or older in /path/to/destination/

See the rsync man page and search online for tutorials for more information.

Evo2.

aaronuq 05-29-2014 09:20 PM

clarify my question
 
Quote:

Originally Posted by evo2 (Post 5179105)
Hi,

not completely sure what you are actually asking, but the command rsync can be used to only copy files if the source file is newer (and different) to the destination file. Eg

Code:

rsync -auv /path/to/source/ /path/to/destination/
will recursively copy files in /path/to/source/ into /path/to/destination/ if the files are missing or older in /path/to/destination/

See the rsync man page and search online for tutorials for more information.

Evo2.

Hi Evo2,

Sorry for my question. Let me clarify it:
For example, if I have a code AAA, which has been used in
~/a1/
~/a2/
~/a3/a4/a5/
...

What I want to do is when AAA has been updated, I also want to update the AAAs in the above folders.
If I used your suggested code or 'cp', the other question is how can I get all the paths containing the code AAA.

Thank you.

Aaron.

evo2 05-29-2014 11:05 PM

Hi,

what do you mean by "a code"? Is this a file? If so you can use soft links. Just put the file in one directory and make the other link to it.

Eg
Code:

mkdir ~/a1/
mkdir ~/a2/
mkdir -p ~/a3/a4/a5/
echo XXX > ~/a1/AAA
ln -s ~/a1/AAA ~/a2/
ln -s ~/a1/AAA ~/a3/a4/a5

Evo2.


All times are GMT -5. The time now is 07:51 PM.