[ Content | View menu ]

Updating a Symlink

Mark Mzyk | October 9, 2010

For future reference, because for some reason this is difficult to Google (and find the correct answer):

To update a symlink without having to delete it and recreate it:

ln -sfn [source file] [target file]

Why the options sfn?

-s is for creating the symlink and not a hard link
-f is of course to force the update, since it already exists.
-n (or -h, they are the same) says not to follow the existing symlink

These options in combination allow a symlink to a directory to be updated in place.

Filed in: General.


  1. Comment by Stefan Mortensen:

    Thank you! This helped me with my problem. The answer to this can be found through Google now :)

    January 12, 2011 @ 09:53
  2. Comment by Mark Mzyk:

    Glad it helped you out Stefan. Hopefully others will find it helpful as well.

    January 17, 2011 @ 21:11
  3. Comment by Ankush:

    Folder structure–>tmp–>(201102.1,201102.2..).… created a symlink(say S) in folder tmp on latest folder inside them. suppose now it is pointing to 201102.2. But when i create a new folder 201102.3..S should point to the latest one..but it doesn’t. How to update it dynamically without again running the command?
    I use the command :
    ln -sfn `ls -t -1|head -1` S

    February 28, 2012 @ 05:49
  4. Comment by Chris:

    Cool beans! Thanks.

    August 4, 2012 @ 12:14