File associations usually are made in the desktop environment, but how to get a list of applications associated with a file using command line?Something like:$ getassoc foo.pdf <CR>$ acroread, okularDoes not need to be a command, can a cat + grep on any Gnome fileI'm using Gnome 2.28.2. A response with other environments would help but not solve.
How to get a list of applications associated with a file using command line
command line;files
There really isn't a centralized resource that you can just query to get at this information. Rather it's maintained in a couple of text files that you can either manually parse if you know where to look or you can use the tool xdg-mime to construct the relationships.ExampleSay I have a PNG file on disk. I can find out its MIME type like this.$ xdg-mime query filetype DSCN4747_DSCN4061_800x600.PNG image/pngI can then query xdg-mime asking it what the association is for this particular MIME type.$ xdg-mime query default image/pngshotwell-viewer.desktop shutter.desktopLooking through the mimeinfo.cache on my system I can find out a bit more about associations for a given MIME type using the following command:$ grep 'image/png' /usr/share/applications/mimeinfo.cache image/png=shutter.desktop;gpicview.desktop;gimp.desktop;eog.desktop;geeqie.desktop;shotwell-viewer.desktop;The desktop definitions in the mimeinfo.cache file are stored here:$ locate shotwell-viewer.desktop/usr/share/applications/shotwell-viewer.desktopAnd it contains the name of the executables you're asking about:$ grep 'Exec=' !$grep 'Exec=' /usr/share/applications/shotwell-viewer.desktopExec=shotwell %fOften times if I just want to launch something, I'll use the tool xdg-open <file|URL> to open a file rather than go and launch the app first, and then open the file.ReferencesHOW TO SET FILE ASSOCIATIONS OF FILE WITH COMMAND LINE IN LINUX