OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

head works similarly. The tail command has a handy feature to continuously show the last n lines of a file that changes all the time. This -f option is often used by system administrators to check on log files. More information is located in the system documentation files.


image

3.3.5. Linking files


3.3.5.1. Link types


Since we know more about files and their representation in the file system, understanding links (or shortcuts) is a piece of cake. A link is nothing more than a way of matching two or more file names to the same set of file data. There are two ways to achieve this:


• Hard link: Associate two or more file names with the same inode. Hard links share the same data blocks on the hard disk, while they continue to behave as independent files.


There is an immediate disadvantage: hard links can't span partitions, because inode numbers are only unique within a given partition.

• Soft link or symbolic link (or for short: symlink): a small file that is a pointer to another file. A symbolic link contains the path to the target file instead of a physical location on the hard disk. Since inodes are not used in this system, soft links can span across partitions.


The two link types behave similar, but are not the same, as illustrated in the scheme below:


Figure 3-2. Hard and soft link mechanism


image


Note that removing the target file for a symbolic link makes the link useless.


Each regular file is in principle a hardlink. Hardlinks can not span across partitions, since they refer to inodes, and inode numbers are only unique within a given partition.


It may be argued that there is a third kind of link, the user-space link, which is similar to a shortcut in MS Windows. These are files containing meta-data which can only be interpreted by the graphical file manager. To the kernel and the shell these are just normal files. They may end in a .desktop or .lnk suffix; an example can be found in ~/.gnome-desktop:


[dupont@boulot .gnome-desktop]$ cat La\ Maison\ Dupont

[Desktop Entry] Encoding=Legacy-Mixed Name=La Maison Dupont Type=X-nautilus-home

X-Nautilus-Icon=temp-home URL=file:///home/dupont

[dupont@boulot .gnome-desktop]$ cat La\ Maison\ Dupont

[Desktop Entry] Encoding=Legacy-Mixed Name=La Maison Dupont Type=X-nautilus-home

X-Nautilus-Icon=temp-home URL=file:///home/dupont

This example is from a KDE desktop:


image


[lena@venus Desktop]$ cat camera

[Desktop Entry] Dev=/dev/sda1 FSType=auto Icon=memory MountPoint=/mnt/camera Type=FSDevice

X-KDE-Dynamic-Device=true

[lena@venus Desktop]$ cat camera

[Desktop Entry] Dev=/dev/sda1 FSType=auto Icon=memory MountPoint=/mnt/camera Type=FSDevice

X-KDE-Dynamic-Device=true

Creating this kind of link is easy enough using the features of your graphical environment. Should you need help, your system documentation should be your first resort.


In the next section, we will study the creation of UNIX-style symbolic links using the command line.


image

3.3.5.2. Creating symbolic links


The symbolic link is particularly interesting for beginning users: they are fairly obvious to see and you don't need to worry about partitions.


The command to make links is ln. In order to create symlinks, you need to use the -s option:


ln -s targetfile linkname


In the example below, user freddy creates a link in a subdirectory of his home directory to a directory on another part of the system:


freddy:~/music> ln -s /opt/mp3/Queen/ Queen


freddy:~/music> ls -l

lrwxrwxrwx 1 freddy freddy 17 Jan 22 11:07 Queen -> /opt/mp3/Queen

freddy:~/music> ln -s /opt/mp3/Queen/ Queen


freddy:~/music> ls -l

lrwxrwxrwx 1 freddy freddy 17 Jan 22 11:07 Queen -> /opt/mp3/Queen

Symbolic links are always very small files, while hard links have the same size as the original file.


Top OS Cloud Computing at OnWorks: