M HYPE SPLASH
// updates

Symlink a directory and automatically sync its content

By Emma Terry

Suppose I have a folder foo with the two content:

data1.txt
cfg.txt

Now I create a new symlink called fo2 which points to directory foo:

cp -s -R /home/user123/foo /home/user123/fo2

It's working okay. But then, I try to made new files in foo folder, say data2.txt. When I opened fo2 folder, it only contains a symlink to data1.txt and cfg.txt data2.txt doesn't exist.

How to make the content of fo2 folder automatically synced with with foo so data2.txt automatically appears in fo2?

ln -s is not an option because I want the content of cfg.txt in foo and fo2 folder to be different. If I use copy -s -R, later I just come inside fo2 folder, delete cfg.txt symlink and recreate a real cfg.txt with different content.

2

1 Answer

If the locations are both on the same filesystem, you should use hard links. Otherwise, you'll have to setup some sort of synchronization, but that will be extremely inefficient in comparison.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy