Difference between revisions of "cmd/ln"
< cmd
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
* Note that a link cannot have the same name as a folder in the same directory. | * Note that a link cannot have the same name as a folder in the same directory. | ||
* The error message "ln: failed to create symbolic link '{{arg|filename}}': File exists" can be maddeningly misleading. It seems to always report the existing file, even when the problem is actually that the ''second'' filename (the link-name) already exists. Translation: | * The error message "ln: failed to create symbolic link '{{arg|filename}}': File exists" can be maddeningly misleading. It seems to always report the existing file, even when the problem is actually that the ''second'' filename (the link-name) already exists. Translation: | ||
− | ** "<tt>'{{arg| | + | ** "<tt>'{{arg|arg 1}}': File exists</tt>" (arg 1 should be {{arg|existing file}}): The link-name is the same as an existing file, possibly a folder. |
− | *** The fact that <code>ln</code> reports the first param instead of the second one seems to be a bug. Yes, the first param is a file that does exist, but that's not the problem. | + | *** The fact that <code>ln</code> reports the first param instead of the second one seems to be a {{l/sub|bug}}. Yes, the first param is a file that does exist, but that's not the problem. |
− | ** "<tt>'{{arg| | + | ** "<tt>'{{arg|arg 2}}': File exists</tt>" (arg 2 should be {{arg|name for link}}): You've got the arguments backwards, and are trying to create a link under the same name as the existing file (to a file which doesn't exist). |
==Example== | ==Example== | ||
I pretty much always get confused as to which is the link and which is the target, so here's an example. You're inside {{fmt/code|/git/futilities/human/ff}} and you want to create a link called "lib" to the "lib" folder at {{fmt/code|/git/futilities/lib}}: | I pretty much always get confused as to which is the link and which is the target, so here's an example. You're inside {{fmt/code|/git/futilities/human/ff}} and you want to create a link called "lib" to the "lib" folder at {{fmt/code|/git/futilities/lib}}: |
Revision as of 13:51, 21 September 2023
ln
is the Linux command for creating a link to a file or folder.
To create a relative link:
ln -r --symbolic ./<existing file> <name for link>
- Relative links will still work even if the folder containing both files (the original and the link) is moved or copied.
- Note that a link cannot have the same name as a folder in the same directory.
- The error message "ln: failed to create symbolic link '<filename>': File exists" can be maddeningly misleading. It seems to always report the existing file, even when the problem is actually that the second filename (the link-name) already exists. Translation:
- "'<arg 1>': File exists" (arg 1 should be <existing file>): The link-name is the same as an existing file, possibly a folder.
- The fact that
ln
reports the first param instead of the second one seems to be a bug. Yes, the first param is a file that does exist, but that's not the problem.
- The fact that
- "'<arg 2>': File exists" (arg 2 should be <name for link>): You've got the arguments backwards, and are trying to create a link under the same name as the existing file (to a file which doesn't exist).
- "'<arg 1>': File exists" (arg 1 should be <existing file>): The link-name is the same as an existing file, possibly a folder.
Example
I pretty much always get confused as to which is the link and which is the target, so here's an example. You're inside «/git/futilities/human/ff» and you want to create a link called "lib" to the "lib" folder at «/git/futilities/lib»:
ln -r --symbolic ../../lib/ ./lib
..or, in other words:
ln -r --symbolic <actual file> <alias>