Linux Classes
Share This With a Friend  
LINUX CLASSES - LINUX COMMANDS

Linux Ln Command

How Do I Link Linux Files?

You can link files together in two ways: with hard links or symbolic links. Creating a Hard Link

The ln command lets a file on your disk be accessed with more than one file name by hard-linking a new file name to it. When you hard-link a file, you create a new file name and connect it with the original file. Hard-linking can let two users share the same file or provide a more convenient way of referencing files buried deep in a series of directories.

Here's an example. Suppose hermie and sigmund are working on the Top Secret Snowgun Project, and the formula for the Snowgun is stored in /home/hermie/projects/snowgun/formula.txt. Sigmund doesn't want to type that long, ugly file name every time he needs to update the file, so he creates a hard link to the file, like this:

ln /home/hermie/projects/snowgun/formula.txt sgformula

The preceding command links the file name sgformula to the file formula.txt contained at the end of that directory string. There's still only one copy of the snowgun formula (formula.txt) on the disk, but now sigmund can access it quickly with the name sgformula (assuming hermie gives him write permission to the file). Interestingly, if hermie deletes his projects/snowgun/formula.txt file, Linux will not remove the file from the file system because sigmund still has a link to it.

Think of the ln command as a way of creating a kind of nickname for a file. By the way, ther e is no parallel to this file linking concept in the DOS world--you'd have to create a second copy of the file and keep the various copies in synch manually to get a similar result.

Creating a Symbolic Link

The type of link we just created is called a hard link. There's another type called a symbolic link. Symbolic links (also called symlinks) work like hard links, but you can do a bit more with them. If you want to create a link to a directory (as opposed to a file), you must create a symlink. Symlinks are also required when linking to a file on a different disk partition or on a network.

To create a symbolic link, add the -s parameter to the ln command, like this:

ln -s /dev/fd0 A:

ln -s /etc/httpd/conf web

The first example allows you to access the floppy drive as drive A, just like in DOS, and the second creates a directory entry called web that can be used instead of /etc/httpd/conf.

Previous Lesson: Task Scheduling
Next Lesson: The Vi Editor

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

No comments yet

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.