I've been admining Linux systems for 25 years, and I still have to check which one it is every time.
I appreciate people saying that it's like `cp` or `mount`, but in my head the natural order of thinking about this operation is reversed: it's "create a link to this file" not "make this file also known as this link." Hence two competing "gut feelings" about which should come first. It also doesn't help that commands like "alias" work the opposite direction ("make a new command that is actually this another command").

Anyway, it was really just an observation that I confuse this all the time, and I'm not the greenest Linux admin around. :)
@monsieuricon i think of it as an html hyperlink
<a href="link">link</a>

@monsieuricon yup, 30 years of Unix/Linux daily use and I still fail this one. Reminds me of USB Type-A 50% chance of plugging it wrong, but failing it *every* time.

BTW, @bagder started a separate thread on this and people are mostly getting it right on the first try - smh...

https://mastodon.social/@bagder/112220659572117434

@denix @monsieuricon @bagder Oh, it's more than that. You have to try 3 times to plug in USB-A. And it's the same for ln. Neither order works the first time.

@denix @monsieuricon @bagder

USB always needs three attempts:

1. Wait, this feels awkward, better try the other way round.
2. No, that's _definitely_ wrong. It _has_ to be the other way round.
3. Ahh...

@monsieuricon I had the same issue for a while.

Especially since I rarely use ln. I try to convince my brain that "-s" would mean "source" even though I know it actually means "symbolic link", just so I remember that the first argument right after the "-s" option is the existing, "source" file.

@monsieuricon 100%. Saying it’s like cp is not helpful as my mental model is the link going the other way (i.e. a link that points to the real file)
@monsieuricon With time everything will fit in place, your gut feelings will be gone, and ln will behave like cp.
(BTW: alias is different: it has a single parameter that is an assignment)

@monsieuricon

Yeah, when I say it's like cp, that doesn't mean it's intuitive. I just have to repeat the mantra.

@monsieuricon I for one suffer the same but because I remember it is the other way around a get confused and have to look :) If there was a system wide config to set it in one of the ways!
@monsieuricon i'm kind of fascinated that people think it worthwhile to try to school *you* of all people, if even @monsieuricon has trouble with this, the problem is not with @monsieuricon, it's with the damn thing :)
@monsieuricon I think of it like cp/mv because the order is "existing thing" "new thing"
@tjk @monsieuricon that's a good way to remember because I think the confusion is that a symlink itself points to a target thing so is the source the symlink itself that points or is thw source the real file and the target the symlink you want to create?

@monsieuricon @dgar every single time - my command history is:

$ man ln

$ ln -s blah blah

Cannot make it stick.

@monsieuricon I feel like we could afford to make a better convention for these tools. Like using > to indicate directionality (I know that's used for redirection, though) or... something. What sort of hints could make these tools easier to use?

@monsieuricon haha while i'm in the "bro it's like cp(1)" crowd, i can appreciate where you're coming from because of memcpy(dest,src, ..).

i tend to find myself in this situation when it comes to unfamiliar assembly syntaxes, or even at&t vs. intel -- is it like cp(1) or is it like memcpy(3)

@monsieuricon my mental model for all commands is that the first file is input, second is output. That said i have always had problems memorizing linux command names and arguments and need to look most of them up…
@monsieuricon I actually remembered this 20 years ago because I gave the -s the alternative meaning of "source". So if you think it like this, you'll never be wrong

@monsieuricon Yes, it's a Sapir-Whorf thing. Some languages are verb-subject-object, and some are verb-object-subject. Yoda even speaks object-subject-verb (in the original, anyway; it's trickier in the German translation).

Don't think of it as a matter of abstract intuition, but as a matter of foreign language intuition. The intuition of consistency, not the intuition of essence.

@monsieuricon In CP/M, copying used to go the other way: pip destination=source. If Unix has been modelled after that, we'd be doing hard links by pip destination<=souce, and symlinks as pip destination<-source.
@riley @monsieuricon oh I missed this comment and posted mine… (CP/M was my ‘first’ OS)
@mia FWIW, I kind of suspect that CP/M's PIP was, in turn, modelled after something that DEC used to ship with PDP-11, the cradle of OSes. Even Unix comes from it!
@monsieuricon
@monsieuricon It won’t help, but in the olden days (at least), mv, cp & ln were all links to the same binary, which examined its argv[0] to see how it was invoked. That was such a weird hack that it’s been easy (for me) to remember all these decades later.
@monsieuricon @monsieuricon how about this trick: it’s “target linkname” because linkname can be omitted for the link to get the same file name and that wouldn’t work the other way around.
@monsieuricon I have a tip: you can omit the second argument, in which case the written filename is deduced from original file. So the second argument is the link. HTH?
@corsac @monsieuricon that's the logic I rely on as well
@corsac @monsieuricon I think you just have changed my professional life as a Sysadmin and now as a Site Reliability Engineer. Thanks for the tip!

@corsac @monsieuricon I actually prefer to do

```ln -s target``` without the linkname and then rename the targetname to the linkname, if at all necessary...

@monsieuricon it’s the same as cp
@raggi @monsieuricon yeah... but not alias; troublesome for those who feel ln is more like alias than cp, right?

@clusterfcku @monsieuricon it's this thinking which leads to the manpage being super confusing.

$tool $existing_path $newly_created_path

forget the minutae, start with the simpler description!

@monsieuricon Most of the time I fall for it, too :D

Sometimes I can remember that you NEED a target, but linkname is optional

@monsieuricon I got around this by thinking of ln as a rename that doesn't remove the old file. And, indeed, they are the same program underneath.
@corbet @monsieuricon "rename that doesn't remove the old file" is just a complicated way to say "cp", right?
@monsieuricon Spoiler: It's like cp.

Firstly, plain "ln" without "-s", and not crossing file system boundaries, is like "mv" without the remove part. You end up having the same file twice, in two directories, or different names in the same, symmetrically, no original and no copy. Doesn't work on directories, though.

Secondly, "ln -s" is like "ln", only the result is not symmetric, but then, it may cross file system boundaries and point to directories.

So if you remember how to use mv, you're fine.

@hennichodernich @monsieuricon

@dj3ei @hennichodernich @monsieuricon

Yeah `mv` is kind of the Star Trek teleporter, and `ln` one of those episodes where you wind up with two of someone.

@monsieuricon I try to remind it by
ln -s from to
@Bandie @monsieuricon I use the -s to remind me it's ln -s source destination
@Bandie @monsieuricon from the link to the target or from the target to the link? 😁

@kaito02 @monsieuricon from the link to the past,

from source to symlink

@monsieuricon @uliwitness “the same as cp”

(not that I don’t have to remind myself of that, but)

@jrose @monsieuricon @uliwitness this trick never worked for my brain , because most of the links I create are relative and then cp wouldn’t work unless you happen to be in the same directory. I don’t think I ever would have learned the order by heart if I hadn’t dealt with so many symlink related compiler issues
@bdwl @monsieuricon @uliwitness I just don’t create links not in the directory, I want tab-completion for the source anyway.
@jrose @monsieuricon @uliwitness the only way I remember is that you can omit the link name, so of course it comes second.

@monsieuricon yeah, it is funny that it is always "from to", when you create link "FROM_target (<-) TO_link_name", but when you list files you get "FROM_link_name -> TO_target"

EDIT: s/target/source/ sounds better in the first case when you create link

To be fair that is horrible terminology.

I remember it as source/input first, to/output last.

Which intuitively feels like the natural flow of things to me.
@monsieuricon I raelly believe there are certain types of information that plop out of your brain immediately after you acquire them and this is one of them lol
@monsieuricon
For me, ln -s src dest
and the source always comes near the '-s'
It helps that I usually 'ls src' to check the path, and then edit that command to insert 'n -', before putting the destination at the end.

@monsieuricon IDK any program that doesn't demand $source $destination as parameters in that order...

So ofc the target is the destination...