通过unix shell命令查找给定文件扩展名的首选应用程序 [英] Finding the preferred application for a given file extension via unix shell commands

查看:228
本文介绍了通过unix shell命令查找给定文件扩展名的首选应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能不是严格的关于编程,但如果我没有找到现成的解决方案,它可能成为一个编程任务:在UNIX上,什么是命令行方法确定



我的理想解决方案是一个命令,阻止我执行以下操作:

  okular foo.pdf 

并允许我这样做,使用我的首选应用程序:

  launch foo.pdf 

我没有通过搜索找到答案,而DIY方法不会工作,

解决方案

在unix上本身

em>这将是用户用来打开它,因为没有操作系统级别的一个首选应用程序的概念。



然而,主要的X桌面环境都定义了一个概念,然后你必须使用他们的设施:




  • gnome-open duh)

  • exo-open [请参阅gnome链接中的评论]

  • xdg-open 可能在许多环境中工作(通常在KDE中工作)[请参阅gnome链接中的注释]

  • kfmclient exec (或 kfmclient4 exec )在KDE中(我还没有找到一个引用 kde-open Rob H建议,并且没有手头的KDE系统来尝试)



现在,Mac OS X提供了 open 命令,它像在查找程序中点击文件一样(也就是说,它询问操作系统...) )




由于 ephemient 在评论中。我不会讨论 mailcap ,因为我从来没有理解它,忘了它存在...


this may not be strictly about programming, but if I find no ready-made solution it may become a programming task: On UNIX, what is a command-line method for determining the user-preferred application for a given filetype?

My ideal solution here would be a command that stopped me having to do the following:

okular foo.pdf

And allowed me to do something like this, working with my set preferred applications:

launch foo.pdf

I found no answer by searching, and a DIY approach wouldn't work as, while I've been using Linux for a while, I have no clue of the internals that manage my preferred applications.

解决方案

On unix per se that would be the one the user used to open it, because there is no OS level notion of a preferred application.

However the major X desktop environment all define such a notion, and then you have to use their facilities:

  • gnome-open in GNOME (duh)
  • exo-open in XFCE [see the comments in the gnome link]
  • xdg-open may work in many environments (reputedly works in KDE) [see the comments in the gnome link]
  • just plain kfmclient exec (or kfmclient4 exec) in KDE (I haven't been able to find a reference to kde-open as Rob H suggests, and don't have a KDE system at hand to try it)

Now Mac OS X provides the open command which works like clicking the file in the finder (which is to say, it asks the OS...)


Several corrections thanks to ephemient in the comments. I won't discuss mailcap, because I never understood it and had forgotten it existed...

这篇关于通过unix shell命令查找给定文件扩展名的首选应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆