Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What does this do?

ln -nsf

I know ln -s creates a symbolic link, not a hard link which means you can delete it and it won't delete the think that it's linking to. But what do the other things mean? (-nf)

Update: okay...so I remembered you can find this stuff out from the command line. Here's what I found out from typing ln --help:

-f, --force                 remove existing destination files
-n, --no-dereference        treat destination that is a symlink to a
                            directory as if it were a normal file

But this still isn't very clear to me what the implications of this are. Why would I want to create a soft/sym link like this?

share|improve this question

migrated from stackoverflow.com Dec 10 '09 at 2:11

This question came from our site for professional and enthusiast programmers.

    
Even if you don't use -s you can delete the link without deleting the original file. Hard links increase the link count of the file so it won't be deleted when you delete only one of the links to it. –  Amuck Dec 10 '09 at 2:08
    
That's not quite the difference between a hard link and a symbolic link. A hard link points to the same bytes (inode) on disk. A soft link points to another file by filename. –  Greg Hewgill Dec 10 '09 at 2:10
    
There are also man pages. i.e. run man ln. Or man man, to learn about that help system. You can get man pages online, too... –  Peter Cordes Dec 10 '09 at 2:40

5 Answers 5

up vote -4 down vote accepted

-f says that if the target of your command is an existing file, it should be removed and replaced by the new link. (Note that in Unix-influenced systems, "file" can include directories, links, pipes, etc.)

-n modifies -f, saying that if the target you specify is an existing symbolic link, it should not be removed.

share|improve this answer
3  
Your description of -n is wrong. -f by itself will not replace a symlink to a directory. When replacing a symlink to a directory, -n is needed to treat the existing symlink like a normal file instead of a directory. –  Brian Mar 24 '11 at 18:12

From the BSD man page:

 -f    If the target file already exists, then unlink it so that the link
           may occur.  (The -f option overrides any previous -i options.)

 -n    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.
share|improve this answer

You can type "man ln" to find such things:

   -f, --force
          remove existing destination files

   -n, --no-dereference
          treat destination that is a symlink to a directory as if it were
          a normal file
share|improve this answer
10  
i still don't exactly understand what that means –  Andrew Dec 10 '09 at 2:14

Here are all the options to ln. You'll find -n and -f in here.

-F If the target file already exists and is a directory, then remove it so that the link may occur. The -F option should be used with either -f or -i options. If none is specified, -f is implied. The -F option is a no-op unless -s option is specified.

 -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.

 -f    If the target file already exists, then unlink it so that the

link may occur. (The -f option overrides any previous -i options.)

 -i    Cause ln to write a prompt to standard error if the target file

exists. If the response from the standard input begins with the character y' or Y', then unlink the target file so that the link may occur. Otherwise, do not attempt the link. (The -i option overrides any previous -f options.)

 -n    Same as -h, for compatibility with other ln

implementations.

 -s    Create a symbolic link.

 -v    Cause ln to be verbose, showing files as they are processed.
share|improve this answer

-f, --force remove existing destination files

-n, --no-dereference treat destination that is a symlink to a directory as if it were a normal file

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.