Symlinks not working when link is made in another directory?

≡放荡痞女 提交于 2019-12-01 16:25:17

If you create a relative path to a symbolic link, it will store it as a relative symbolic link. Symbolic links are relative to the location the link is in, not the location where it was created or opened.


Please use absolute path or path relative to the link.

Change:

ln -s originals/original.txt copies/copy.txt

To:

# absolute
ln -s /path/to/originals/original.txt copies/copy.txt

# relative
cd copies
ln -s ../originals/original.txt copy.txt

You can also use relative path to achieve this. like

cd copies
ln -s ../originals/original.txt copy.txt

This will work

when you open the symbolic link which it tries to refer to the file from the copies directory and since that doesn't exist you are getting that error.

When you use relative or absolute path this problem will get solved.

Consider an example where you want to symlink your application logs to somewhere else which may be a directory which is mounted to a secondary directory whose size won't effect your server to stop working. Now the mounted directory will be target for you and you should create a symlink to this directory for your logs directory.

Suppose your application directory is /home/ubuntu/my_app and once you start your application it will generate a log directory inside your my_app directory. Now the end goal is to divert the disk usage burden to the mounted directory and currently don't have our log directory present in our app directory. So just go ahead and follow the below steps:

mkdir /path_to_mounted_directory/log
ln -s /path_to_mounted_directory/log /home/ubuntu/my_app_log

This will first create a directory named log in mounted section and will map your application logs to this directory. Any file you add in the application log folder will be linked to the mounted directory automatically and thus you can read these files fro anywhere you want, either from the original logs directory or from the mounted folder.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!