-1

When I move a directory elsewhere, a symblink to it will become invalid.

The way I update a symlink mylink is first going into the directory, and then running ln -s "$PWD" mylink, and then mv mylink to the invalid symlink.

I can't create the new symlink in the same directory of the invalid symlink using the above ln command, because ln: failed to create symbolic linkmylink': File exists, so I have to create it elsewhere and then there is an additional mv step.

I wonder if an existing invalid symlink can be edited directly, just like editing a text file in a text editor such as Emacs?

Tim
  • 101,790

1 Answers1

2
ln -sf --no-target-directory /path/to/new/dir link

The option --no-target-directory (aka -T) prevents a new symlink to be created in the linked directory but is only available on GNU systems.

On FreeBSD or Apple OS/X, you'd use:

ln -sF /path/to/new/dir link
Hauke Laging
  • 90,279