3 ms·
If you’re having trouble remembering the order of arguments to ln, remember that it’s the same way around as cp. Worked for me. That is, if before there is som
by School-Cotton 2y ago
If you’re having trouble remembering the order of arguments to ln, remember that it’s the same way around as cp. Worked for me.
That is, if before there is something at /some/path but not /another/path , after running
ln /some/path /another/path
there will be something there (same as cp).
- agumonkey 2y agothanks, i still need to ignore the fact that the link on the right points to the left then
- mturmon 2y agoThis is what made the “ln” argument order click for me as well. Another piece of this parallel is that (with cp and mv) you can omit naming the destination file - you often just name the directory: cp /other/dir/foo.txt . The corresponding shortcut with ln is not naming the destination at all, and the symlink is created in the working directory: ln -s /other/dir/foo.txt Both of the above are my most common usage patterns, and the abbreviation of the second argument in both helps reinforce the parallel between cp, mv and ln.
- stouset 2y agoThe one that always trips me up is that `ln` is “dumb” about how it handles the first argument. If the first argument isn’t an absolute path, it must be relative to the second argument, and not to pwd. ln ./foo ./bar/baz ./bar/baz will be a symlink whose literal contents are `./foo` so it will look for foo in the same directory (bar), rather than in bar’s parent directory. This is totally backwards from how other utilities behave. Which is completely understandable if you know what it’s doing under the hood. But it is counterintuitive and surprising.
- tavianator 2y agoAt least with GNU coreutils, you can use `-r`/`--relative`
- stouset 2y agoTIL!
- bbkane 2y agoI've never internalized this, so I usually stick to using absolute paths... Not a solution for all problems, but it works for me most of the time.
- stouset 2y agoAbsolute paths will break if, for example, the target and source are in the same directory but you move the directory. Sometimes you semantically want absolute paths (I want to symlink a thing to /bin/foo), sometimes you want relative paths (I want to symlink a thing to something in a nested directory).