Live data from Hacker News

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

reddit.com

31–40 of 127 posts

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

#31
You can create multiple links with the original names at once with commands like:

  ln -s path1/files* path2/
or

  ln -s path1/* .
Doing that helped me remember the order because I knew my command could end with a directory as the destination and links would be created there.

Sometimes hardlinks are useful too. You don't always need -s

Edit: Why was this downvoted? I didn't see anyone else mention it until after my post and to me this was an easier way to remember the order than comparing it to "cp".

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

#32
post #3
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.

I used to have this problem too, and then I read the linked article and now remember the relationship between ln and cp and never got it wrong since. Also I wonder how many people can say the same thing as the article and still get upvoted.

I said it in fewer words and didn't add any adsense junk.

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

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

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?

Except volume dials.

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

#37
post #12
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.

I suspect strcat and strcpy were parameterized as such to match memcpy. Why memcpy was parameterized in that order, I am not certain.

memcpy(lvalue, rvalue, size)

lvalue == write location rvalue == read location

It comes from assignment syntax where the left hand side is the target of the assignment and the right hand side is the source. So this makes a ton of sense in C.

OTOH, the Bourne shell was built independent of the C programming language. The Bourne shell inherited a bit from its predecessor the Thompson shell which introduce the concept of command piping. In this case, all operations followed the pattern of data flowing to the right. This is the opposite of how assignment works in all programming languages where data flows to the left.

That's why shell commands generally move data from left to right based on their argument ordering.

FWIW, tar is unique because tar wasn't meant to do archiving to files. If you just did `tar c directory' it would archive the directory to a tape device. The `f' flag is there to redirect the output to a file (instead of the default tape device). So `tar cf foo.tar directory' is not backwards, it just uses an unusual argument convention. The modern form would be `tar --file=foo.tar create directory'.

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

#38
post #36

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?

Except volume dials.

And sometimes doorknobs, but those are abstract enough you wouldn't expect them to behave the same. Unless you're talking about screwing the dial itself clean off.

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

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

Most assemblers have fx

  mov a,b
as from b to a.
Post reply on HN