Linking files

by Sanju 2009-11-09 15:36:11

Linking files in Linux

In linux we can link files together in two ways:
> Hard links
> Symbolic links

Creating a Hard Link

A hard link is simply an additional directory entry pointing to the same data.

To avoid copying a file in several places on the same disk, it is a better idea to use a link:

ln existingname newname



Thus the same file can have several names (and be in several directories at the same time).

Creating a Symbolic 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 /var/log /logs


The above code creates a symbolic link '/logs' to the directory '/var/log'. If you enter 'cd /logs', you are actually in the directory '/var/log'.

Tagged in:

976
like
0
dislike
0
mail
flag

You must LOGIN to add comments