How to symlink a file in Linux?

2018-12-31 09:30发布

I want to make a symbolic link in Linux. I have written this bash command where the first path is the folder I want link into and the second path is the compiled source.

ln -s '+basebuild+'/IpDome-kernel/kernel /home/build/sandbox/gen2/basebuild/IpDome-kernel/kernal 

Is this correct?

标签: linux symlink
18条回答
浅入江南
2楼-- · 2018-12-31 09:48

Creating Symbolic links or Soft-links on Linux:

Open Bash prompt and type the below mentioned command to make a symbolic link to your file:

A) Goto the folder where you want to create a soft link and typeout the command as mentioned below:

$ ln -s (path-to-file) (symbolic-link-to-file)

$ ln -s /home/user/file new-file

B) Goto your new-file name path and type:

$ ls -lrt (To see if the new-file is linked to the file or not)

Example:

ls -lrt

lrwxrwxrwx 1 user user 24 Aug 6 23:40 new-file -> /home/user/file

Note: Where, A -> B Means, A is symbolically linked to B

查看更多
临风纵饮
3楼-- · 2018-12-31 09:49

If you are in the directory where you want to create symlink, then ignore second path.

cd myfolder
ln -s target

It will create symlink of target inside myfolder.

General syntax

ln -s TARGET LINK_NAME
查看更多
闭嘴吧你
4楼-- · 2018-12-31 09:49

To create a symbolic link /soft link, use:

ln -s {source-filename} {symbolic-filename}

e.g.:

ln -s file1 link1
查看更多
孤独寂梦人
5楼-- · 2018-12-31 09:49

I find a bit confusing the terminologies "target" and "directory" in the man information.

The target is the folder that we are symlinking to and the directory the actual symlink (not the directory that you will be symlinking to), if anyone is experiencing the same confusion, don't feel alone.

This is my interpretation of creating a Symlink (in linux):

ln -s /FULL/PATH/FOLDER-OR-FILE-SYMLINKING-TO NAME-OF-YOUR-SYMLINK

You can navigate to the folder where you want to create the symlink and run the command or specify the FULL PATH for your symlink instead of NAME-OF-YOUR-SYMLINK.

cd /FULL/PATH/TO/MY-SYMLINK-PARENT-FOLDER
ln -s /FULL/PATH/FOLDER-OR-FILE-SYMLINKING-TO NAME-OF-YOUR-SYMLINK

OR

ln -s /FULL/PATH/FOLDER-OR-FILE-SYMLINKING-TO /FULL/PATH/TO/MY-SYMLINK-PARENT-FOLDER/NAME-OF-YOUR-SYMLINK

I hope this helps to those (still) slighly confused.

查看更多
牵手、夕阳
6楼-- · 2018-12-31 09: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)
查看更多
与风俱净
7楼-- · 2018-12-31 09:54
ln -s TARGET LINK_NAME

Where the -s makes it symbolic.

查看更多
登录 后发表回答