The
Missing Symlink
Randal L. Schwartz
Symbolic links were not present in the first version of UNIX that I used.
That would be UNIX V6, back in 1977, when the UNIX kernel size was under 32K.
It's hard to imagine anything under 32K being associated with UNIX these days.
But somewhere in the bowels of the University of California at Berkeley, in
the early 80s, the boys working on BSD concocted a scheme to rectify two of
the biggest problems with hard links: they couldn't be made to a directory,
and they didn't want to point to another mounted filesystem. Their solution
was that now common feature, a symbolic link.
A symbolic link is essentially a text string that sits in place of a file.
When the symbolic link's filename is accessed, the UNIX kernel replaces the
filename with its text value instead, like a macro expansion. This all happens
transparently to the executing program (unlike some other popular operating
systems).
From the shell, symbolic links are easy enough to create:
ln -s /usr/lib/perl5 ./Lib
which makes a reference to Lib in the current directory hop over to
/usr/lib/perl5/. From Perl, this same step is:
symlink("/usr/lib/perl5", "./Lib") or die "$!";
We can see this is so with:
ls -l
which will show something like:
..... Lib -> /usr/lib/perl5
indicating this redirection is going on. That same fact is apparent to Perl,
like so:
my $where = readlink("Lib");
print "Lib => $where\n";
But what if /usr/lib itself is also a symbolic link, say to /lib?
Well, the system nicely picks that up when it's looking down the steps from /usr
to /usr/lib, redirects that to /lib, and continues from there to
look for perl5.
|