08/04 postscript I received supplements and corrections in the comments, so I will make corrections as appropriate.
When I was learning shell commands, I was addicted to symlinks, so I will leave a memorandum. ~~ I don't know if this is a best practice, but use absolute paths as much as possible to generate symlinks. ~~
This is not a best practice as it depends on the occasion. This is because if you want to manage the files and links of the link source collectively, you will be vulnerable to changing the installation location.
A symbolic link is one of the functions of the file system of the operating system (OS), and is a mechanism that creates another file that points to a specific file or directory so that the main body can be referenced through it. IT Glossary e-Words
We recognize that symbolic links in Linux are like shortcuts in Windows.
The purpose is similar, but the reality is quite different. In addition, Windows also has symbolic links (using a feature called reparse points). Shortcuts are just launchers with information to open the specified file in the app, but symbolic links are files that can be used as an alternative to the specified file. @angel_p_57
The command used to create a symbolic link is: hoge.jpg is an arbitrary file name, and fuga is an arbitrary directory name. Here, a symbolic link of a file called hoge.jpg is generated in the fuga directory.
$ ln -s hoge.jpg fuga
Note: In this case, "if the fuga directory already exists" it will run as intended. Without the fuga directory, a symbolic link named fuga would be created in the same directory.
If you set $ ln -s hoge.jpg fuga /
, it will be a command to be executed if the directory exists.
(I referred to the comments I received)
~ / Picture / konosuba.jpg symbolic link, I want to generate it in ~ / Picture / foobar.
Suppose the current directory is ~ / Picture.
~/Picture $ ln -s konosuba.jpg foobar
konosuba.jpg is generated in the foobar directory, but First of all, this is a mistake.
The symbolic link of konosuba.jpg that exists in the current directory is not generated in the foobar folder specified as a relative path ... **. ** **
The symbolic link konosuba.jpg generated in the foobar directory is Relative path from your own perspective konosuba.jpg In other words, let's think about going to refer to konosuba.jpg in the same directory.
In other words, it creates a mysterious file called a symbolic link that references itself.
(This is because "konosuba.jpg ", which is the first argument of the shell command, is read as a relative path based on the position of the symbolic link itself.)
Suppose the current directory is ~ / Picture.
~/Picture $ ln -s ../konosuba1.jpg foobar
konosuba.jpg is generated in the foobar directory. This is the correct answer. The symbolic link konosuba.jpg generated in the foobar directory is It is generated as a link that refers to "../konosuba1.jpg " when viewed from its own position.
It may not be a problem if you get used to it, but honestly I felt confused.
In that case, use the option -r (--relative). The command will automatically determine the relative position. With ln -s hoge.jpg fuga /, the created symbolic link fuga / hoge.jpg causes a circular reference and is useless, but with ln -s -r hoge.jpg fuga /, fuga / hoge. It will create a suitable link called jpg-> ../hoge.jpg. @angel_p_57
$ ln -s ~/Picture/konosuba.jpg ~/Picture/foobar
With an absolute path, the risk that the referrer is not intended can be greatly reduced. If the directory structure gets complicated, I feel like it's going to be ridiculous, but for the time being, I shouldn't make a mistake ...
I don't feel like I was able to write it well, so I'll make some changes as needed ...
Getting Started with Linux Command Line Ubuntu Manuals
Recommended Posts