Log in

No account? Create an account
Lindsey Kuper [entries|archive|friends|userinfo]
Lindsey Kuper

[ website | composition.al ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

ln, link -- make lindsey insane [Apr. 21st, 2008|11:12 pm]
Lindsey Kuper

Given one or two arguments, ln creates a link to an existing file source_file. If target_file is given, the link has that name; target_file may also be a directory in which to place the link; otherwise it is placed in the current directory. If only the directory is specified, the link will be made to the last component of source_file.

I can never remember how to use ln. I always look at the man page, and then I always get it wrong anyway. I don't understand how such a durned simple thing can be so hard, but it is!

The confusing part is that the existing file is "source", and the new thing you're making is "target". To me, in this context, a "target" should be something that already exists. Picture an archery target, with arrows flying into it from potentially many places. Many sources, one target! Right?

But no, they want you to think of "source" as the thing being pointed to, and "target" as the thing that points. Can someone suggest some kind of mental picture or mnemonic that will make me remember this? I'm tired of getting it wrong.


[User Picture]From: pixelherder
2008-04-22 06:48 am (UTC)
This precise thing has been Proggit before. There were lots of ideas there on how to remember it, the most prevalent being to think of how you would do cp or mv.
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-04-22 07:42 am (UTC)


cp existing new
ln -s existing new


I never thought of that! Thanks, dude on reddit!

(Reply) (Parent) (Thread)
[User Picture]From: stereotype441
2008-04-22 07:57 am (UTC)

Re: Thanks!

Man, I've been waiting something like 12 years for that.
(Reply) (Parent) (Thread)
From: freyley
2008-04-22 08:36 pm (UTC)

Re: Thanks!

this is basically how I figured it out, too, except that it was a special trick to ln that taught me it

ln /path/to/original/file

will make file in this directory, a link to the thing specified. The link file is an optional argument. This really helped me figure out that, regardless of the stupid names, it wants the thing that exists first.
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-04-23 01:48 am (UTC)

Re: Thanks!

man, that behaviour always bites me. I keep typing things like:
ln -s file /tmp/

and I end up with a self-recursing link like so:
lrwxrwxrwx 1 jes5199 jes5199 3 2008-04-22 18:47 new -> new

jes5199@electra:~$ cat /tmp/new
cat: /tmp/new: Too many levels of symbolic links

Edited at 2008-04-23 01:49 am (UTC)
(Reply) (Parent) (Thread)
[User Picture]From: karaksindru
2008-04-22 06:58 am (UTC)
Think of Robin Hood (or other skilled archer) standing in one spot and quickly hitting six or ten or thirty different targets? ;)
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-04-22 07:43 am (UTC)
I like it!
(Reply) (Parent) (Thread)
[User Picture]From: underwhelm
2008-04-22 10:58 am (UTC)
God. I have the same problem.
(Reply) (Thread)
[User Picture]From: joyquality
2008-04-22 03:03 pm (UTC)
Machine translation has the source/target vocabulary problem. There were historical reasons (that I'm now forgetting, but it has something to do with World War II) that the "source" language and the "target" language were exactly opposite of what you would thing they'd be (ie, the target is the language being translated from and the source is the language being translated to). In recent years, a lot of researchers have decided that's stupid and have flipped the terms around, but some people still use them the other way and it can get confusing.
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-04-22 04:12 pm (UTC)

That's really interesting! That's a context in which it does make sense, to me, for "source" to be the existing thing and "target" to be the new thing. It was the same way in the ICFP programming contest, where they started with a source image and generated a target image.

ln seems different from those situations because you're not creating something really new. You've already got a target, and you're pointing to it again from a new source.

I suppose you're still creating a new file, though. And I guess I shouldn't expect the file system to care if the new file I create is the result of great effort or not...

(Reply) (Parent) (Thread)
[User Picture]From: joyquality
2008-04-22 05:38 pm (UTC)
I realize that my original comment was a little ambiguous and I'm not sure from your response that my meaning was clear. The historical alignment is like, say you've got a document in German that you want to translate to English. In that case the source language is English and the target language is German. Nowadays most people will call German the source language and English the target language, which I think is more intuitive.
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-04-22 08:10 pm (UTC)
Nah, that's what I thought you meant the first time. It's just that now I'm confused about the One True Meaning of "source"/"target"!

I know! I'll just start using "real"/"fake" all the time, even in situations where it is wildly inappropriate.
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-04-23 01:45 am (UTC)
I keep reading you sentence about ICFP and it doesn't seem to support joyq's use of those words. Isn't the "new thing" in language translation the document that hasn't been written yet? in the "source" language?

also, this.
(Reply) (Parent) (Thread)
[User Picture]From: lindseykuper
2008-04-23 02:36 am (UTC)
But didn't she say that that was the usage that researchers had decided was stupid?

To me, the language of the document that hasn't been written yet is the target language.
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2008-04-23 02:00 am (UTC)
debian's docs are better! (even though they use the word "target" in the opposite meaning)

ln - make links between files

ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)

In the 1st form, create a link to TARGET with the name LINK_NAME. In
the 2nd form, create a link to TARGET in the current directory. In the
3rd and 4th forms, create links to each TARGET in DIRECTORY. Create
hard links by default, symbolic links with --symbolic. When creating
hard links, each TARGET must exist.

Edited at 2008-04-23 02:01 am (UTC)
(Reply) (Thread)
[User Picture]From: lindseykuper
2008-04-23 02:32 am (UTC)
Yeah! And therefore Ubuntu's.

Now I'm sshing around my places to see who's got what. I forgot TextDrive ran FreeBSD. Living in a world of choice is nice!
(Reply) (Parent) (Thread)
[User Picture]From: vruba
2008-05-05 11:14 pm (UTC)

Many years ago I was in a situation where it was desirable to have /dev/toilet point to /dev/null (as part of a conversion that also involved uid 0 being named woot, etc. … it was a simpler time). I ran into this and eventually figured out I wanted ln /dev/null /dev/toilet. So then my mnemonic was that “null toilet” makes more sense than “toilet null”. I’m not proud of this.

freyley’s explanation is really lucid, and that’s how I’ll think of it from now on.

(Reply) (Thread)