Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have file A, and using 'ln -s A B', I have B.

When I open, edit and save B, now B is not symlink anymore. It's just a new copy of A.

  • Is this expected behavior? I use Mac OS X, and I wonder it's common in UNIX.
  • In this case, is there any way to keep B as a (soft link) to A? Or, make B as the hard link would be the only way to solve this issue?
  • What's the advantage of using soft link than hard link?


The editor that I use is 'TextMate' on Mac.

share|improve this question
What editor are you using? – Jason Axelson Sep 2 '10 at 3:44
Report a bug in the editor - not nice behaviour. – Jonathan Leffler Sep 2 '10 at 4:49
up vote 6 down vote accepted

This happens when the editor saves to a temporary file, removes the original, then renames the temporary file. Not all editors follow this behavior, but most do for reliability reasons. And making it a hard link won't help since the link would be erased regardless.

share|improve this answer
If the editor in question is emacs the behavior can be turned off, but it does that for a pretty good reason and you should think before canceling it. – dmckee Sep 2 '10 at 3:04
I do this all the time with VIM, and the links don't get broken. – Nathan Fellman Sep 2 '10 at 3:21
@Nathan as Ignacio stated not all editors follow this behaviour. vim does not. – matthias krull Sep 2 '10 at 9:31
@mugen: I know. I was not trying to contradict him, but rather to suggest one editor that does work well with links. – Nathan Fellman Sep 2 '10 at 12:41
@Nathan: vim usually follows the method described by Ignacio (which reduces the potential damage if something bad happens while saving the file, like a full disk or a power failure: this method guarantees that you will have at least either the old or the new version of the file, and the change is atomic). But when it figures that this method would have bad side effects (symbolic link, file with hard links, unwritable directory, …), vim modifies the file directly. – Gilles Sep 2 '10 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .