Red Hat Linux

Working with Links in Linux

RHKIn a Linux file system, it is very useful to be able to access a single file from different locations. This discourages you from copying a file to different locations, where subsequently different versions of the file may come to exist. In a Linux file system, you can use links for this purpose. A link appears to be a regular file, but it’s more like a pointer that exists in one location to show you how to get to another location.

In Linux, there are two different types of links. A symbolic link is the most fl exible link type you can use. It points to any other file and any other directory, no matter where it is. A hard link can be used only to point to a file that exists on the same device.
With symbolic links, there is a difference between the original file and the link. If you remove the original file, the symbolic link won’t work anymore and thus is invalid.
A hard link is more like an additional name you’d give to a file. To understand hard links, you have to appreciate how Linux file systems work with inodes. The inode is the administration of a file. To get to a file, the file system reads the file’s inode in the file system metadata, and from there it learns how to access the block where the actual data of the file is stored. To get to the inode, the file system uses the file name that exists somewhere in a directory. A hard link is an additional file name that you can create anywhere in a directory on the same device that gives access to the same file system metadata. With hard links, you only need the original file name to create the hard link. Once it has been created, it isn’t
needed anymore, and the original file name can be removed. In general, you’ll use symbolic links, not hard links, because hard links have some serious limitations.

To create a link, you need the ln command. Use the option -s to create a symbolic link. Without this option, you’ll automatically create a hard link. First you’ll put the name of the original file directly after the ln command. Next you’ll specify the name of the link you want to create. For instance, the command ln -s /etc/passwd ~/users creates a symbolic link with the name users in your home directory. This link points to the original file /etc/

Resources : Red Hat® Enterprise Linux® 6 Administration
Real World Skills for Red Hat Administrators

Leave a Reply

Your email address will not be published. Required fields are marked *