Symbols do not work when the link is made in another directory?

Wow, I've never used symbolic links before, but this is really awesome:

bash-3.2$ echo "weird" > original.txt bash-3.2$ mkdir originals bash-3.2$ mv original.txt originals/ bash-3.2$ cat originals/original.txt weird bash-3.2$ mkdir copies bash-3.2$ ln -s originals/original.txt copies/copy.txt bash-3.2$ cat copies/copy.txt cat: copies/copy.txt: No such file or directory bash-3.2$ ls copies/copy.txt copies/copy.txt bash-3.2$ ls -l copies/copy.txt lrwxr-xr-x 1 zach staff 22 Dec 22 01:23 copies/copy.txt -> originals/original.txt bash-3.2$ cat originals/original.txt weird bash-3.2$ cat copies/copy.txt cat: copies/copy.txt: No such file or directory bash-3.2$ cd copies/ bash-3.2$ cat copy.txt cat: copy.txt: No such file or directory 

Why can't I cat symlink in the copy directory?

If I make a symbolic link from copies of /, I can handle it. If I make a symbolic link in the current directory, I can handle it too. If I create a symbolic link in the current directory, and then move it to a copy of /, I get "copy / copy.txt: there is no such file or directory".

+6
source share
3 answers

If you create a relative path to a symbolic link, it will save it as a relative symbolic link. Symbolic links refer to the location where the link is located, and not to the place where it was created or opened.


Please use an absolute path or path relative to the link.

Edit:

 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 
+15
source

You can also use the relative path to achieve this. as

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

It will work

when you open a symbolic link that it is trying to link to a file from the copy directory, and since this does not exist, you get this error.

When you use a relative or absolute path, this problem will be solved.

+5
source

Consider an example in which you want to symbolize application logs elsewhere, which may be a directory that is mounted on a secondary directory whose size will not cause your server to stop working. Now the installed directory will be your target, and you must create a symbolic link for this directory for your log directory.

Suppose your application directory is / home / ubuntu / my _app, and as soon as you start the application, it will create a log directory inside your my_app directory. Now the ultimate goal is to divert the load of disk usage to the mounted directory and currently there is no our log directory present in our application directory. So just follow these steps:

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

First, a directory will be created called log in installed section and will map your application logs to this directory. Any file that you add to the applicationโ€™s log folder will be automatically linked to the mounted directory, and you can read these files anywhere, either from the original log directory or from the mounted folder.

+1
source

Source: https://habr.com/ru/post/904300/


All Articles