10.5. Symbolic links

In general, symbolic links within a top-level directory should be relative, and symbolic links pointing from one top-level directory to or into another should be absolute. (A top-level directory is a sub-directory of the root directory /.) For example, a symbolic link from /usr/lib/foo to /usr/share/bar should be relative (../share/bar), but a symbolic link from /var/run to /run should be absolute. 9 Symbolic links must not traverse above the root directory.

In addition, symbolic links should be specified as short as possible, i.e., link targets like foo/../bar are deprecated.

Note that when creating a relative link using ln it is not necessary for the target of the link to exist relative to the working directory you’re running ln from, nor is it necessary to change directory to the directory where the link is to be made. Simply include the string that should appear as the target of the link (this will be a pathname relative to the directory in which the link resides) as the first argument to ln.

For example, in your Makefile or debian/rules, you can do things like:

  1. ln -fs gcc $(prefix)/bin/cc
  2. ln -fs gcc debian/tmp/usr/bin/cc
  3. ln -fs ../sbin/sendmail $(prefix)/bin/runq
  4. ln -fs ../sbin/sendmail debian/tmp/usr/bin/runq

A symbolic link pointing to a compressed file (in the sense that it is meant to be uncompressed with unzip or zless etc.) should always have the same file extension as the referenced file. (For example, if a file foo.gz is referenced by a symbolic link, the filename of the link has to end with “.gz” too, as in bar.gz.)