How can I symlink a file in Linux?

ID : 420

viewed : 110

Tags : linuxsymlinklinux

Top 5 Answer for How can I symlink a file in Linux?

vote vote

99

To create a new symlink (will fail if symlink exists already):

ln -s /path/to/file /path/to/symlink 

To create or update a symlink:

ln -sf /path/to/file /path/to/symlink 
vote vote

81

ln -s TARGET LINK_NAME 

Where the -s makes it symbolic.

vote vote

79

ln -s EXISTING_FILE_OR_DIRECTORY SYMLINK_NAME 
vote vote

69

ln -s target linkName 

You can have a look at the man page here:

http://linux.die.net/man/1/ln

vote vote

51

(Because an ASCII picture is worth a thousand characters.)

An arrow may be a helpful mnemonic, especially since that's almost exactly how it looks in Emacs' dired.

And big picture so you don't get it confused with the Windows' version

Linux:

ln -s target <- linkName 

Windows:

mklink linkName -> target 

You could also look at these as

ln -s "to-here" <- "from-here" mklink "from-here" -> "to-here" 

The from-here should not exist yet, it is to be created, while the to-here should already exist (IIRC).

(I always get mixed up on whether various commands and arguments should involve a pre-existing location, or one to be made.)

EDIT: It's still sinking in slowly for me; I have another way I've written in my notes.

ln -s (target exists) (link is made) mklink (link is made) (target exists) 

Top 3 video Explaining How can I symlink a file in Linux?

Related QUESTION?