For example,

the executable emacs:

lrwxrwxrwx 1 root root      23 Jun  9  2012 /usr/bin/emacs -> /etc/alternatives/emacs
llrwxrwxrwx 1 root root     18 Jun  9  2012 /etc/alternatives/emacs -> /usr/bin/emacs23-x
lrwxrwxrwx 1 root root       9 May 16  2013 /usr/bin/emacs23 -> emacs23-x
-rwxr-xr-x 1 root root 6772008 May 16  2013 /usr/bin/emacs23-x

the executable emacsclient:

lrwxrwxrwx 1 root root      29 Jun  9  2012 /usr/bin/emacsclient -> /etc/alternatives/emacsclient
lrwxrwxrwx 1 root root      28 Jun  9  2012 /etc/alternatives/emacsclient -> /usr/bin/emacsclient.emacs23
-rwxr-xr-x 1 root root   18256 May 16  2013 /usr/bin/emacsclient.emacs23
  1. why are there links to links in system directories?

    If we need to link for some reason, in the examples, why links from a file in /usr/bin to a file in /etc/alternatives/ then back to a file in /usr/bin, rather than links the two files in /usr/bin directly?

  2. is there a command that can deference a link until reaching a non-link file?

p.s. Ubuntu

  1. why are there links to links in system directories?

It gives you a flexible way to chose what default program, or program version you will use. From man update-alternative:

Debian's alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name. For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default. The system admin‐ istrator can override this and cause it to refer to /usr/bin/ed instead, and the alternatives system will not alter this setting until explicitly requested to do so.

2, is there a command that can deference a link until reaching a non-link file?

If you have readlink utility, you can:

readlink -f link


$ readlink -f /usr/bin/nawk

Or you can use Perl abs_path function from core module Cwd:

$ perl -MCwd=abs_path -le 'print abs_path(shift)' /usr/bin/nawk 



This is part of the alternatives system. It allows admins to configure various utilities that do the same (or similar) things as the default on that system.

Examples are configuring which version of Java is the system default - OpenJDK or Oracle's offering.

You can list the alternatives on your system using:

alternatives -l

You'll notice that all of those listed by this command are also in /etc/alternatives as symlinks.

The namei utility is useful for following symlinks:

$ namei /usr/bin/cdrecord
f: /usr/bin/cdrecord
 d /
 d usr
 d bin
 l cdrecord -> /etc/alternatives/cdrecord
   d /
   d etc
   d alternatives
   l cdrecord -> /usr/bin/wodim
     d /
     d usr
     d bin
     - wodim
  • If cdrecord is a link to wodim, then you do not have cdrecord but a defective fork that you should definitely avoid. There are more than 100 documentd bugs in that fork. – schily Sep 16 '15 at 10:53
  • The original cdrtools is here: sourceforge.net/projects/cdrtools/files – schily Sep 16 '15 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.