2 Synthesis‎ > ‎Computing‎ > ‎Linux‎ > ‎Shell‎ > ‎Files‎ > ‎

Links

The Problem

Normally in the physical world if one has two containers then an object has to be in one or the other. Similarly in a library a book must be on one shelf or the other. In a physical filing system a file must be in one place or the other.

The Linus filing system reflects this in its tree structured filing system i.e. there is a root which contains files and directories. Each directory can contain other files and directories. So it is add infinitum.

Imagine that we wanted to classify files each on an a science experiment in physics, chemistry or biology it might seem easy until we realise that some experiments might involve a combination of these and therefore have good reason to be placed in more then one place. The fact is that a file may need to be placed under multiple classifications.

What is Ironic is that although classification systems used in the physical world for physical things have to consider the idea that a thing can only be in one container (filing cabinet or bookshelf) at a time, computer filing systems don't work like this anyway, and the whole notion of a file appearing in just one directory is simulated by the operating system!

The difficulties of putting things like this means that the file on Arduino based Robots appears under one or the other meaning that people looking in one of those places might miss it.

The Temporary Solution

Soft Links

Classification systems that allow an item to appear in more than one class are called faceted classification systems, and Linux can be used to try to create a sort of faceted scheme with a bit of work and the command line.

In the Ubuntu desktop is is possible to create a soft link by a <ctrl><shift> left mouse drag. This can also be done with a command like;

    ln -s <file-path>

The link will be created in the current directory. You can add a <file-name> if you don't want the link to be given the same name as the file it links to.

An absolute path like /home/tom/Desktop/foo will only be broken if the destination file or directory is moved but can be put anywhere.

A relative path like ../qqq/foo will be broken if the destination file or directory is moved with respect to the directory that contains the link, and so this means you can copy or move the structure in any way that keeps their relative positions in tact. This link must be contained in the same directory as qqq to work.

Copying can a problem. When we copy an absolute soft link it points to the same file as the soft link it is a copy of. So if we want a copy of a soft link to to point to the copy of the file then it has to be a relative softlink i.e. the softlink path has to be relative to the location where the soft link is intended to operate. 

Hard Links

Files and directories are actually represented in the filing system by a number called an inode and when we see a named file in a directory it is actually just a hard link to the inode and thus the file. Another hardlink can be created;

   ln <file-path>

The link will be created in the current directory. You can add a <file-name> if you don't want the link to be given the same name as the inode it links to.

Now there are apparently two possibly differently named files that actually refer to the same file on the storage medium. The actual data will only be deleted when both these references have been deleted.

Linux does not allow users to create hard links to directories, only to files, only the root account can create hard links to directories. The reason for this is that it is quite easy to mess up the file system creating directories that contain themselves! this causes problems for programs that recurs the file system tree.

One can create hard links on mass with;

cp -l

Which copies a file structure but instead of copying the files it just puts hard links!
 

What to Do

Personally I am sticking to relative soft links. I have to create them using the command line because there is no drag and drop method. To create absolute links just drag and drop while holding down <ctrl><shift>






















UNFINISHED CONTENT


© Tom de Havas 2011. The information under this section is my own work it may be reproduced without modification but must include this notice.







Comments