如何获取可以在Linux中打开特定文件扩展名的程序列表? [英] How to get list of programs which can open a particular file extension in Linux?

查看:48
本文介绍了如何获取可以在Linux中打开特定文件扩展名的程序列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我试图获取Linux中已安装的程序列表,例如,这些程序可以打开特定的文件扩展名 .jpg .如果不是全部,则应至少列出默认程序.

Basically I am trying to get list of programs in Linux which are installed and can open particular file extension .jpg for example. If not all, At-least default program should get listed.

推荐答案

Linux(内核)不了解文件类型到应用程序的映射.如果要使用Gnome程序,可以查看 https://people.gnome.org/~shaunm/admin-guide/mimetypes-7.html .对于KDE,还有另一种机制.每个工具箱都可以根据需要定义它.程序员可以使用默认值,也可以不使用默认值.因此,它只是特定于应用程序的!

Linux (the kernel) has no knowledge on file types to application mapping. If you want to use Gnome programs you can look at https://people.gnome.org/~shaunm/admin-guide/mimetypes-7.html. For KDE there is another mechanism. Each toolkit can define it as it likes. And the programmer can use the defaults or not. So it is simply application specific!

您想实现什么?

如果(双击)图标或文件名上的资源管理器/浏览器应用程序,则资源管理器/浏览器将精确查找文件类型.通常,这是通过mime类型字典来实现的.但是程序如何查找文件类型并可能执行另一个程序仅与编写该程序的程序员有关.Gnome和KDE之类的GUI工具链对此主题有很多支持,因此您对每个应用程序系列都具有基本的一致性.

If you (double) click with a explorer/browser application on an icon or file name, exactly the explorer/browser looks for the file type. Typically this is realized via mime type dictionary. But how a program looks for the file type and maybe execute another program is only related to the programmer who writes that program. The GUI tool-chains like Gnome and KDE have a lot of support for that topic and so you have basic conformity for each family of applications.

如果您想知道应用程序是如何完成这项工作的,请使用 strace 启动它.但是要挖掘大量数据是非常困难的.

If you want to know how a application do the job, start it with strace. But it is quite hard to dig into the huge amount of data.

此外,您还可以查看 xdg-open .许多程序使用此帮助程序来启动应用程序.例如:如果您使用 strace 启动Dolphin,则会发现类似 lstat64("/etc/xdg",{st_mode = S_IFDIR | 0755,st_size = 4096,...}的行.)= 0 (点击文件后).

Also you can take a look for xdg-open. Many programs use this helper to start applications. As an example: If you start Dolphin with strace you will find a line like lstat64("/etc/xdg", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 after clicking on a file.

您可以使用以下命令从命令行运行

you can run from command line with:

xdg-open <file-name>

您可能还想看看注册了文件类型的应用程序:/usr/share/applications/*.desktop

You maybe also want to have a look for applications which registers for file types: /usr/share/applications/*.desktop

在这里您可以找到每个桌面文件中为应用程序注册的某些mime类型.例如.的 audiacity 为:

Here you can find in each desktop file some mime-types which are registered for the applications. E.g. for audiacity is:

MimeType=application/x-audacity-project;audio/flac;audio/x-flac;audio/basic;audio/x-aiff;audio/x-wav;application/ogg;audio/x-vorbis+ogg;

jpg 为例:

$ xdg-mime query filetype <any-jpg-file>
image/jpeg

$ grep 'image/jpeg' -R /usr/share/applications/*
...
/usr/share/applications/mimeinfo.cache:image/jpeg2000=kde4-kolourpaint.desktop;gimp.desktop;

因此您可以看到 gimp jpg

这篇关于如何获取可以在Linux中打开特定文件扩展名的程序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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