43

The alternatives command (package chkconfig) on RHEL/Fedora manages symlinks which link a generic name to one of the alternative implementations. For example, mta group of symlinks can be provided by Sendmail and Postfix (to implement i.e. sendmail command):

alternatives --display mta

While I can --display a group of symlinks, I need to guess its name first (i.e. mta).

Can I simply list all possible configurable symlink groups (like mta) to pick from?

The reason is that I forget some group names occasionally.

uvsmtid
  • 847
  • 1
  • 6
  • 12

4 Answers4

45

On Debian (but not Fedora or RHEL), to see a list of all "master alternative names":

update-alternatives --get-selections

--get-selections list master alternative names and their status.

And for each of those listed, you can run --list $ALTERNATIVE_NAME, e.g.

update-alternatives --list editor

--list name Display all targets of the link group.

If you would like to see a list of all alternatives in their respective groups, you could run the following in fish shell:

for alternative in (update-alternatives --get-selections)
    echo $alternative 
    update-alternatives --list (echo $alternative | cut -d" " -f1)
    echo
end | pager

The (ba|z)?sh syntax should be something similar.

To change the alternatives, run sudo update-alternatives --config $ALTERNATIVE_NAME

Noumenon
  • 105
  • 4
kzh
  • 608
  • 1
  • 7
  • 11
  • 1
    On my Fedora 12 `update-alternatives` is a symlink to `alternatives`: `/usr/sbin/update-alternatives -> alternatives`. So, option `--get-selections` does not show anything (exit with error showing usage). – uvsmtid Jul 03 '16 at 13:43
  • 1
    I didn't read the question properly. Sorry. This is for Debian. I was trying to find the same thing as you and I can't up with this answer. I wonder if I should delete my answer? – kzh Jul 03 '16 at 13:45
  • Up to you. If you think it is correct under some circumstances and might be useful for anyone else, it is worth to just leave it. – uvsmtid Jul 03 '16 at 14:06
20

The exact answer is (RHEL):

ls /var/lib/alternatives

Directory /etc/alternatives maintains flat long list of all symlinks mixing masters and slaves together. Slave symlinks cannot be used with alternatives --display [symlink] command.

At the same time directory /var/lib/alternatives contains status information (including master-slave relationship) for each group in shortened list of file names all of which can be directly used with --display option. For example, /var/lib/alternatives/java:

alternatives --display java
uvsmtid
  • 847
  • 1
  • 6
  • 12
  • 5
    On Ubuntu 12.04, there is no `/var/lib/alternatives`, it seems to be `/var/lib/dpkg/alternatives`. – Hibou57 Jul 12 '14 at 08:59
  • 1
    Great answer, Thanks! One addition: on Debian and Armbian it's `/etc/alternatives` instead of `/var/lib/alternatives` – Alexey Vesnin Aug 20 '17 at 02:00
5

The simplest answer would be...

ls /etc/alternatives
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
-1

On Ubuntu 12.04 (may be some prior versions too, to be checked) and probably Debian too (to be checked):

ls /var/lib/dpkg/alternatives

List it just to get configurable alternative names, as entries in this directories are not links. By the way, there may be compressed file in this directory, so the names listed there, can't always be used as‑is. Ex. I have a /var/lib/dpkg/alternatives/psql.1.gz

Hibou57
  • 139
  • 4
  • Not really helpful, as the question clearly states that it applies to RedHat Enterprise Linux. The RHEL way of configuring is properly described in the other answers. – Kosi2801 Nov 17 '14 at 16:18