Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 1999 > 9908

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.



MarketPlace

Free Download Speeds Up PCs
Make Your PC Faster --New Diskeeper 2008 Speeds Up PCs --Download Free Trial Now!

Online Crash Analysis
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.

WinDev 12 - Powerful IDE
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Wanna see your ad here?