next up previous contents
Next: Commands and shell Up: Files and Commands that Previous: Some Useful Details: Ownership,   Contents

I-nodes and Links

In Unix, file names and files are conceptually separate. It is perfectly possible to have two different names for the same file. In that case, there are simply two different directory entries that point to the same file. In order to avoid confusion, the term ``i-node" is used to refer to the file as a physical entity. So we would say that a file with two names is an ``i-node" having two directory entries that point to it. We refer to the connection between a directory entry and an i-node as a ``link". The ``ln" command can be used to link a new name to an i-node. The format is ``ln old-name new-name". Note that it is perfectly possible for the two names to be in different directories. So you and your friend could share a file by using the ``ln" command to create a second link to it. Note that the ownership information is part of the i-node. So the one that created the file initially would still own it. But it would appear identically in both of your directories. The file will continue to exist until both of you delete it. That is, the ``rm" command really only removes the link from a name to an i-node. The i-node goes away when there are no more links to it. There is an additional kind of link, a ``symbolic link". This is a link from one name to another name, instead of from a name directly to an i- node. Suppose you wanted to make ``myprog" in your directory point to your friend's version: ``~smith/myprog". You could of course say ``ln ~smith/myprog myprog". However if your friend ever deleted myprog and created a new one with the same name, your link would continue to point to the same i-node, namely the old file. So you might prefer to use a symbolic link: ``ln -s ~smith/myprog myprog". This says that myprog in your directory is linked to ~smith/myprog, whatever it may happen to it. That is, instead of being linked to a particular physical file, it is linked to the name. Most people do not use symbolic links. A normal link (technically called a ``hard link") will normally do the right thing. There are special provisions in the editors so that when you edit a file that has more than one link, all of the links are maintained. But there are some situations where a symbolic link may make sense. Unless you are a super-user, you can't create a hard link between two directories. So one of the more common uses of symbolic links is for directories. Suppose you have a friend who is working with you on files in the directory /u2/smith/cs231/source. You may not want to type all of that every time you want to access one of his files. So you might do ``ln -s /u2/smith/cs231/source smith". Then if you refer to ``smith/foo" you will really get ``/u2/smith/cs231/source/foo".
next up previous contents
Next: Commands and shell Up: Files and Commands that Previous: Some Useful Details: Ownership,   Contents
Arthur Chou 2001-09-04