1

I have two directories newdir and otherdir and would like to update a symlink, that initially pointed to otherdir to newdir.

When I run:

> ln -s otherdir symlink 

I see a symlink:

> ls -al symlink
symlink -> otherdir

When I run:

> ln -sFf newdir symlink

I would expect symlink -> newdir, but I see the old link when I run:

> ls -al symlink
symlink -> otherdir

And I also noticed that a new symlink exists:

> ls -al symlink/newdir
symlink/newdir -> newdir

Is there a way to prevent ln from interpreting the destination path as parent directory ? Or is the only way to prevent this from happening to remove the link first ?

1

Use the -h option:

-h    If the target_file or target_dir is a symbolic link, do not follow it. 
      This is most useful with the -f option, to replace a symlink 
      which may point to a directory.
$ ln -shf newdir symlink
$ ls -al symlink
symlink -> newdir

You must log in to answer this question.

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