How to get list of programs which can open a particular file extension in Linux?

一世执手 提交于 2021-02-10 05:42:06

问题


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.


回答1:


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!

What do you want to achieve?

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.

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.

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>

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

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;

For your example with 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;

So you can see that gimp is one of the default applications for jpg




回答2:


The place to start looking is at the mailcap (/etc/mailcap) and MIME-types, e.g., in /etc/mime.types in Debian (the filename and path will vary according to who provides it).

The mailcap file gives some rules for opening a file, while MIME-types lists the known filetypes with a tag that allows multiple applications to know about the file types.

Except for embedded or reduced-functionality systems (such as those based on busybox), you would find these files on almost every UNIX-like system.



来源:https://stackoverflow.com/questions/30662334/how-to-get-list-of-programs-which-can-open-a-particular-file-extension-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!