Live data from Hacker News

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

reddit.com

111–120 of 127 posts

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

#111
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?

Because in the final result, the link points to the original. The directory listing will even say

    link -> original
So naturally you want to say that in the command, "make a link that points to the original".

I had a friend who gave up and made an alias that sorted out which of the arguments existed and did The Right Thing.

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

#112
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.

C calls are trying to mirror the assignment statement in the programming language: target := source

"cp" is trying mirror how we do things in real life: if you want to take some things from one place and put them in another, you first pick them all up (hence the first argument), walk over to the destination, and then put them down.

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

#113
post #16

I've always used complex numbers as a mnemonic: real + imaginary, a + bi (obviously the file is real and the softlink is "imaginary"). http://en.wikipedia.org/wiki/Complex_number

The real/imaginary concept is exactly what I use too. I sort of recall being able to use the real/imaginary concept with other Unix commands as well, but I can't recall which ones off the top of my head.

rm only has the real component before you issue it and the imaginary one afterwards ;)

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

#117
post #44

Earlier quoted context omitted.

This is a crime against usability IMO. Another comment mentioned that tar takes arguments as "target source" rather than "source target". Ever notice that for everything in the world that screws, like valves or screws or bottle caps, counter-clockwise loosens and clockwise tightens? How is it we got the whole world to agree on that convention, but software is 50/50 on how we order the source and destination?

I don't feel it's a crime. For that matter, I don't even prefer one over the other. For "mv A B" I've no problem saying either mv into A the contents of B or mv the contents of A into B

Who does prefer one over the other? The lack of consistency is the real problem.

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

#118
post #57

Earlier quoted context omitted.

This happens to be the first comment in the thread on Reddit.

Exactly. Why the GP's comment is currently at +33 when all it does is restate the main point of the story in a confusing way (by introducing from/to into the mix) is beyond me.

Probably because most of the people upvoting him didn't bother to read the story.

I am often guilty of this myself. At first I used to read all of the stories that were linked to on HN, along with the comments. But I quickly learned that the comments were often much more interesting/useful than the stories themselves.

So now I just look at the comments first, by default. And only in exceptional cases do I actually bother to read the article. There's just not enough time..

HN is an overwhelming firehose of information even without reading every article that seems interesting. But reading the comments can usually quickly give you a good feel for whether the story is worth reading or not. In this particular case, I think not.

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

#119
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.

It's so similar to cp that GNU cp has cp -l from to

Good, but cp -l is for hard links and cp -s is for symlinks. Most of the time people want the latter.

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

#120

Earlier quoted context omitted.

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.

Thanks! I always wondered what was the purpose of -t. Never occurred to me it was to allow you to reverse the order of args.
Post reply on HN