From RootdevWiki

Jump to: navigation, search

We all know you can create a symbolic link as follows:

~$ ln -s file foo
~$ ls -la foo
~$ lrwxrwxrwx 1 cdibble cdibble 4 2006-06-19 15:02 foo -> file

Did you know you can repoint a Symlink without having to remove and recreate it first?

But how? I hear you cry...

Simple, just add a -f switch if the target is a file:

~$ ln -sf file2 foo
~$ ls -la foo
~$ lrwxrwxrwx 1 cdibble cdibble 4 2006-06-19 15:02 foo -> file2

or -fn if it's a directory:

~$ ln -s dir1 foo
~$ ls -la foo
~$ lrwxrwxrwx 1 cdibble cdibble 4 2006-06-19 15:02 foo -> dir1
~$ ln -fsn dir2 foo
~$ ls -la foo
~$ lrwxrwxrwx 1 cdibble cdibble 4 2006-06-19 15:02 foo -> dir2

Magic huh?