Creating a Symbolic Link

A symbolic link (or symlink) is a file that points to another file. Symlinks are very useful for linking files that continually move about, or to link library dependencies to their appropriate location. As an example, assume there is a file that continually changes in location. Instead of remembering the new location every single time, it is more appropriate to create a symlink and update this link whenever the file's location changes. This way, users don't have to worry about where the file is, or even be aware of it's location change, as the symlink file will point them to the right place.

A symlink is created using the command below. The filename refers to the file you wish to access, while linkname refers to the name of the symlink file.

    ln -s filename linkname

In the example below, a symlink is created in a public directory to point to a file inside a user's account. By doing this, others can view the file via the symlink without physically accessing the file itself:

    % ln -s ~/public_html/link2dvd.txt mylink

A symlink can be identified by running the ls command. Everything after the -> refers to the file the link is pointing to.

 
    % ls -al mylink 
         0 lrwxrwxrwx    1 angies   angies         47 Mar 12 14:26 mylink 
                                          -> /import/kamen/1/angies/public_html/link2dvd.txt

A symlink can be deleted like a normal file:

 
    %  rm mylink
Loc Van Huynh 2007-03-15
Please complete our new website survey