update-alternatives 命令

       update-alternatives creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system.

       It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time.  For example, many systems have several text editors installed at once.  This gives choice to the users of a system, allowing each to use a different editor,  if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.


whereis editor (当输入editor命令时,调用的是/usr/bin的edior命令,因为PATH路径中包含/usr/bin)

editor: /usr/bin/editor /usr/bin/X11/editor /usr/share/man/man1/editor.1.gz

ls  /usr/bin/editor -al

lrwxrwxrwx 1 root root 24 May 12  2013 /usr/bin/editor -> /etc/alternatives/editor

ls /usr/bin/editor -al

lrwxrwxrwx 1 root root 18 May 12  2013 /etc/alternatives/editor -> /usr/bin/vim.gnome(editor命令最终是调用/usr/bin/vim.gnome)


update-alternatives 用于配置 /etc/alternatives 对应命令的可选调用路径

例如: 

查看editor命令的候选选项

sudo update-alternatives --display editor

 editor - auto mode
  link currently points to /usr/bin/vim.gnome
  /bin/ed - priority -100
  slave editor.1.gz: /usr/share/man/man1/ed.1.gz
  /bin/nano - priority 40
  slave editor.1.gz: /usr/share/man/man1/nano.1.gz
 /usr/bin/vim.basic - priority 30
  slave editor.1.gz: /usr/share/man/man1/vim.1.gz
  slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
  slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
  slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
  slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
  /usr/bin/vim.gnome - priority 60
  slave editor.1.gz: /usr/share/man/man1/vim.1.gz
  slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
  slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
  slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
  slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
 /usr/bin/vim.tiny - priority 10
  slave editor.1.gz: /usr/share/man/man1/vim.1.gz
  slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
  slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
  slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
  slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
 Current 'best' version is '/usr/bin/vim.gnome'.

 (editor 命令的候选选项有6个,当前链接为/usr/bin/vim.gnome


增加命令的候选选项

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/gedit 300

 /usr/bin/editor : generic name (or alternative link)
                             A name, like /usr/bin/editor, which refers, via the alternatives system, to one of a number of files of similar function.

editor:  alternative name. The name of a symbolic link in the alternatives directory.

 /usr/bin/gedit : path

300:  priority(默认选中优先级最高的)


更改命令的链接选项

sudo update-alternatives --config editor

  

There are 5 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/vim.gnome   60        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.gnome   60        manual mode
  5            /usr/bin/vim.tiny    10        manual mode

Press enter to keep the current choice[*], or type selection number:(输入你要选定的选项)




 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值