3.10.2 Symbolic links

Next: 3.11 Job Control Up: 3.10 Managing file links Previous: 3.10.1 Hard links

  Symbolic links are another type of link, which are somewhat different than hard links. A symbolic link allows you to give a file another name, but it doesn’t link the file by inode.

The command ln -s will create a symbolic link to a file. For example, if we use the command

# ln -s foo bar we will create the symbolic link bar pointing to the file foo. If we use ls -i, we will see that the two files have different inodes, indeed.

# ls -i foo bar 22195 bar 22192 foo


However, using ls -l, we see that the file bar is a symlink pointing to foo.

# ls -l foo bar
lrwxrwxrwx 1 root root 3 Aug 5 16:51 bar -> foo
-rw-r--r-- 1 root root 12 Aug 5 16:50 foo

The permission bits on a symbolic link are not used (they always appear as rwxrwxrwx). Instead, the permissions on the symbolic link are determined by the permissions on the target of the symbolic link (in our example, the file foo).

Functionally, hard links and symbolic links are similar, but there are some differences. For one thing, you can create a symbolic link to a file which doesn’t exist; the same is not true for hard links. Symbolic links are processed by the kernel differently than hard links are, which is just a technical difference but sometimes an important one. Symbolic links are helpful because they identify what file they point to; with hard links, there is no easy way to determine which files are linked to the same inode.

READ  Firewall and Proxy Server HOWTO

Links are used in many places on the Linux system. Symbolic links are especially important to the shared library images in /lib. See Section 4.7.2 for more information.    

Next: 3.11 Job Control Up: 3.10 Managing file links Previous: 3.10.1 Hard links

Matt Welsh