Live data from Hacker News

I always forget the argument order of the `ln -s` command

reddit.com

61–70 of 127 posts

Re: I always forget the argument order of the `ln -s` command

#61
post #2

I used to have this problem. Then I realized that if I want to really copy a file, I type $cp file_from file_to and that $ln -s link_from link_to has a very similar effect to the cp command above. I haven't messed this up ever since.

The problem with "from" and "to" is - which is the from and which is the to? Is the "from" the file/dir I want to copy "to" a link? Or is the "from" the name of a link I want to point "to"? The dual meaning of some terms that the concept of links and making links creates causes a lot of this confusion, IMHO. Are we using terminology that refers to the act of creating the link or that refers to the direction of the li…

"to" is an entity that doesn't exist yet.

Re: I always forget the argument order of the `ln -s` command

#62
post #2

I used to have this problem. Then I realized that if I want to really copy a file, I type $cp file_from file_to and that $ln -s link_from link_to has a very similar effect to the cp command above. I haven't messed this up ever since.

That's what I would have intuitively thought. But I swear it worked the other way sometimes!

Re: I always forget the argument order of the `ln -s` command

#63
post #8

My god, this thing always keeps biting me. It seems so obvious now with that cp-mnemonic. But it makes me wonder, why does everyone do it wrong in the first place?

At least for me, it's because I say in my head "link $FOO to $BAR", which must be typed "ln -s $BAR $FOO".

My theory is that we're used to see symlinks as part of the "ls -l" output, which lists the link name first, and then the target. Later, we want to create symlinks as we're used to see them (linkname -> target).

Re: I always forget the argument order of the `ln -s` command

#64
post #41

Earlier quoted context omitted.

tar is like that because of command lines tar [args] [one thing] [list of things] it'd be wierd if it was tar [args] [list of things] [filename] ... but i will admit i frequently make that mistake.

But, as a counterpoint, if you want to copy several things to a folder, you do: cp [args] [list of things] [destination folder]

But you can also do

  cp [args] -t [destination folder] [list of things]
The same is true of mv. This is useful if you are piping filenames to xargs.

Re: I always forget the argument order of the `ln -s` command

#65
post #2

I used to have this problem. Then I realized that if I want to really copy a file, I type $cp file_from file_to and that $ln -s link_from link_to has a very similar effect to the cp command above. I haven't messed this up ever since.

This phrasing confused me more.

`$ ln -s link_from link_to` would imply the reverse behavior. How does a symlink point from the actual file to the thing-that-looks-like-a-file-but-is-really-a-symlink? The file doesn't even know whether there are symlinks pointing to it.

Applying your definitions of "link from" and "link to", this:

Googlehttp://google.com/>Google;

creates a link from google.com to the hyperlink on your site.

I find the top reddit comment:

    cp existing new
    ln -s existing new
much, much more useful. You want to create a new link pointing to an existing file, which has the same ordering as when you use cp to create a new file with the content of an existing file.

Re: I always forget the argument order of the `ln -s` command

#66
post #14
post #10

Does anyone know why C calls like 'strcpy' and 'strcat' are the opposite of this? strcat(target, source) strcpy(target, source) But, in SH... cp source target I feel like these things were developed around the same time, by the same community. I've always wondered if there was a reason for the different perspective.

Probably in order to be consistent with assignment.

I think it's more to do with the requirement that mandatory arguments have to go before optional ones (it wouldn't work the other way round).

Re: I always forget the argument order of the `ln -s` command

#67

Earlier quoted context omitted.

The problem with "from" and "to" is - which is the from and which is the to? Is the "from" the file/dir I want to copy "to" a link? Or is the "from" the name of a link I want to point "to"? The dual meaning of some terms that the concept of links and making links creates causes a lot of this confusion, IMHO. Are we using terminology that refers to the act of creating the link or that refers to the direction of the li…

"to" is an entity that doesn't exist yet.

Exactly! The rule is for that commands of two letters in length (cp, ln, mv) the file on the end is the one that gets created. For commands of three letters in length (tar, zip) the file that gets created is the first one. And then there's the exceptions that prove the rule like scp and ssh.

And people say Linux isn't user-friendly! :)

Re: I always forget the argument order of the `ln -s` command

#68
Yeah, the UNIX ln command is full of trouble.

* The arguments order is just the opposite of common sense. It has taken me years to really remember it, and I still have to think a little every time I use it.

* The default is to create hard link, which you almost never want. And if you do want them, you are probably doing it wrong. Making hard links is just asking for trouble.

I've read that Plan9 has somewhat corrected this whole problem. At least there is no ln command at all. Instead one uses bind, mount, and unmount. Of which bind is most similar to ln -s, but with arguments in reversed order.

Re: I always forget the argument order of the `ln -s` command

#70
post #2

I used to have this problem. Then I realized that if I want to really copy a file, I type $cp file_from file_to and that $ln -s link_from link_to has a very similar effect to the cp command above. I haven't messed this up ever since.

This phrasing confused me more. `$ ln -s link_from link_to` would imply the reverse behavior. How does a symlink point from the actual file to the thing-that-looks-like-a-file-but-is-really-a-symlink? The file doesn't even know whether there are symlinks pointing to it. Applying your definitions of "link from" and "link to", this: Google http://google.com/>Google ; creates a link from google.com to the hyperlink on y…

I say in my head "link symboliicaly from HERE to THERE"

It took me a long time till I realized that saying it thus made me always recall it properly.

Post reply on HN