Hacker News new | ask | show | jobs
by terra_t 5673 days ago
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.

9 comments

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:

<a href="http://google.com/>Google</a>;

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.
Less ambiguously:

  cp    existing_thing new_thing
  ln -s existing_thing new_thing
That's exactly how I remember it too

  ln -s 'the one that exists' 'the one that doesnt exist'
I actually say that to myself as I'm typing the command. Since I started doing that, I've never gotten it wrong.
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.

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.
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 link?

Similarly, I don't think it helps that the usage text and manpage for ln refer to "target"s.

(I know what you mean by your examples but I wanted to share my pet theory as to why this is always so hard to remember)

"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! :)

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.
I used to just cheat. I normally cd-ed to the directory I wanted the link in then just let the name of the link be the name of the file, so I didn't need a destination file name, just ln -s source_file
In my experience the more variable argument often comes last, presumably for easy reuse. For example...

  $chown user1 file1
  $chown user1 file2

  $ln -s file1 file2
  $ln -s file1 file3
...seems more likely than...

  $chown user1 file1
  $chown user2 file1

  $ln -s file1 file2
  $ln -s file3 file2
That's the reason behind a most of the argument orders in the Haskell standard library: To ease Currying.
Why did you do that? Now I really want to implement a const and flip for text arguments :)
That could be a nice command line tool. Please include a Data.Function.on, and find a way to make it useful.

flip would actually be quite useful for me on grep. I often search the some corpus of text, but change the pattern.

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.

Not the most helpful of advice for those that can't remember which way round the cp command takes its arguments either...
That's what I would have intuitively thought. But I swear it worked the other way sometimes!