Mathematical symbol for the natural logarithm, which is log to the base e

Ln is an abbreviation for Lane, often in specifying addresses.

Example: "27 Grasshopper Ln" in place of "27 Grasshopper Lane"
Ln is a family of programming languages used to study the concepts of computability and write Turing Machine and other models.

The programming language L belongs to this family.

ln -s

For those of you who don't know, the Unix command 'ln -s' is used to create a symbolic link, which is a pointer to a real file or directory on your computer system. It's very useful and fun.

Now, there are two parameters to the command--one is the link and the other is the actual file that you're linking to. The problem is, I can't tell you in which order they are supposed to be placed on the command line. You would think this is simply because I forgot. However, that is not the case.

The 'ln -s' command seems to have the strange side effect that the order of the parameters are always the opposite of what they are the first time you type it. It's true--at least it always seems that way to me. I think, "This time, haha, I've got it right," and it never is. I believe this is a trick and if I looked at the source code I'd be able to verify it.


QuestionMarkPlatypus: Oh, sure, tell me that now. But when I open up a shell on my Linux box, this will have changed, I assure you. . .

ln -s

There is a trick to working out how to do this right. Pretend that the 'ln -s' is in fact a cp or a mv.

Now put the file names as you would if you where using the above commands to create the new file and bingo the right usage every time.

Definition

The strict definition of the natural logarithm is as an integral: "ln(x) is the integral from 1 to x of dt/t". In functional form:

         / x
        |     dt
ln(x) =  \   ----
          |   t
         / 1

Observations

First, it's clear that ln(1) should be zero. Next, for 0<x<1, the integral is negative (just as it should be). Also, "ex is the inverse of ln(x)", which is to say that eln(x)=x and ln(ex)=x.
Further, it should now be clear why the harmonic sum (H(x)) diverges; the sum of the reciprocals of the positive integers up to (possibly including) x is an approximation of ln(x) (in the limit as x approaches infinity, H(x)-ln(x)=y, the Euler-Masceroni constant, which is roughly 0.57 or so).

Properties

All the properties that logarithms have are applicable to the natural logarithm, because of the curious property that ln(x)=logex (the logarithm to base e of x). Further, the prime number theorem states that:

       pi(x)*ln(x)
lim    -----------  = 1
x->oo       x

There are many other properties of ln (e.g., ln(a*b) = ln(a) + ln(b)), but an exhaustive list would be... exhausting.

ln -s

The reason that ln -s file target is confusing is that, even though it is consistent with cp and mv, unlike those commands, it is not consistent english language.

Compare the english sentence:

Copy a file to a place

with the shell command

cp a_file a_place

Notice how they're the same way round? Now compare the english

Create a link thingy to the file boing

In english, we say this the other way round, whereas the shell command is still in the same direction as cp and mv:

ln this_file_exists make_this_point_to_that

and that's why it is confusing you sometimes.

A solution (or two)

I present, for your use, two very simple perl scripts which I've personally used for years to solve this problem. Choose one, stick it in your ~/bin (unless, of course, you've been scared by 'Why putting ~/bin or . in your $PATH is a bad idea').

They both rely on the fact that when you are creating links, you generally want to create a link that doesn't exist, to a file that does. Both these scripts accept the arguments either way round and create the link the way that makes sense. The downside of this is that you can't create a new link over an old one without rm-ing it first.

The first one is dead simple. It checks which way round you meant and passes them off to the real ln program. It will handle hard links or symlinks (with the -s option) but not any other option since they tend to do with overwriting old links, and we can't do that*.


#!/usr/bin/perl

if ($ARGV[0] eq '-s'){
        $s="-s";
        shift;
}

if (-e $ARGV[0]){
        die ("Cannot overwrite existing file") if -e $ARGV[1];
        `ln $s $ARGV[0] $ARGV[1]`;
}else{
        die ("Target file does not exist") unless -e $ARGV[1];
        `ln $s $ARGV[1] $ARGV[0]`;
}
and the other is slightly more interesting in that it does the symlinks itself, without calling the old ln program. The upshot of this is that you could replace the /usr/bin/ln on your system with it. But I really wouldn't recommend it.
#!/usr/bin/perl

use File::Spec("rel2abs");

if ($ARGV[0] eq '-s'){
        shift;
}

if (-e $ARGV[0]){
        die ("Cannot overwrite existing file") if -e $ARGV[1];
        symlink (File::Spec->rel2abs($ARGV[0]),File::Spec->rel2abs($ARGV[1]));
}else{
        die ("Target file does not exist") unless -e $ARGV[1];
        symlink (File::Spec->rel2abs($ARGV[1]),File::Spec->rel2abs($ARGV[0]));
}

* I did play with the idea of checking to see if one file is a symlink (if they both already exist) and overwriting that one, but it seems a big ambiguous and dangerous.
Thanks to OldMiner for helping me sort the confusing nature of my w/u :-)

Log in or register to write something here or to contact authors.