How could I copy a directory somewhere else (perhaps temp) and ensure it stays in sync with the original?

StackOverflow https://stackoverflow.com/questions/20503356

Question

So I want to write a script that will allow me to temporary move some files/directories to a new location (perhaps temporarily or sometimes permanently) so that any changes made on the original or the copied version get updated to the other (so they both are always in sync with one another).

I was thinking I could use a hardlink, but that does not work for directories which I would like to support. I found this script that is supposed to make it work with directories but I was hoping that there is a better way (and cross platform maybe): https://github.com/selkhateeb/hardlink

It does not seem like a symlink would work either as I would like any changes to stay in sync.

Any help would be great, thanks.

Was it helpful?

Solution

You are right that hardlinks don't work on directories. Have you considered,though, symlinking the base directory? In other words, if the two directories that you want to keep in sync are /some/path/original and a non-yet-existent /other/path/copy, do:

ln -s /some/path/original /other/path/copy

This way, any change to original shows up in copy and vice versa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top