Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What I want is to have multiple copies of the same file, and whenever I edit one of them, they all get updated. I thought Hard Links would solve my problem. So, I used the command ln as described in Wikipedia. However, when I changed the original file, the linked one didn't change.

Did I misunderstand what hard links are supposed to do?

  • If yes:
    • Then what's the difference between ln and cp?
    • How can I do what I want?
  • If no:
    • Why didn't it work?
    • How can I get it to work?
share|improve this question

migrated from stackoverflow.com Oct 29 '11 at 18:08

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 0 down vote accepted

Perhaps the editor is doing some weird things, like copying the file to some temporary location, or whatever.

My suggestion would be on the contrary: Edit the file using always the same path, and use symbolic links (ln -s) everywhere.

And version control systems might be relevant too.

share|improve this answer
    
If I use symbolic links in a repo (that point to a file outside the repo) and then push the repo to github, will others that clone the repo be able to use the file? That's why I wanted to use hard links. –  Lea Verou Oct 29 '11 at 11:17
    
I would believe that yes, but the easiest thing is to try. And you could have the symlink made by the building process (e.g. with a Makefile rule). –  Basile Starynkevitch Oct 29 '11 at 11:22
    
Unfortunately, turns out you can't even link to .js files that are symlinks :( –  Lea Verou Oct 29 '11 at 11:41
    
I'm not sure to understand what you mean. Perhaps you need to configure the web server serving those .js files to follow symlinks. –  Basile Starynkevitch Oct 29 '11 at 11:48

Following the "tutorial" found on http://en.wikipedia.org/wiki/Ln_%28Unix%29#Hard_link, I've done the exact same commands on Mac Os X and it definitely does not work as it should be.

I thought at first that Mac Os X had a different behavior, so I tried on Ubuntu but I got exactly the same result :(

So the answer I can give you is "you did understand well according the explanation from wikipedia". Or perhaps we're both confused ?

Sorry I could not help you more :(

share|improve this answer
    
I think I get it, thanks to Basile: The editor saves the file to a different place in the disk every time. If it's just that file pointing to that space in the disk, the first place will get deleted. However, because there's a 2nd hard link pointing there, the OS leaves it there. So the first link points to the first file still, but the 2nd file now occupies another place in the disk. –  Lea Verou Oct 29 '11 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.