Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I haven't done anything with Linux in a decade, so I hope this question is still relevant. I've always wanted to know how Linux did this, and I just now thought of it again.

In the Windows OS world, files are associated with an application by their extension. For example, foo.txt may be opened with notepad (txt). And foo.xls would be opened with Excel (xls).

With Linux, file names didn't have extensions (do they now?), so how did it know what app to use to open a file? If a file was called foo, and I double-clicked it, it would actually open within the correct application. How?

share|improve this question

migrated from Feb 23 '13 at 0:37

This question came from our site for professional and enthusiast programmers.

Try man 1 file. – cnicutar Feb 22 '13 at 21:24
Linux has no notion of file associations with apps. It's a feature of file managers, and each one may do it its own way. – Barmar Feb 22 '13 at 21:44
up vote 3 down vote accepted

Actually, Linux itself doesn't care about file types, it only cares if a file is executable or not, and this is set by the properties of a file, not the content. However, the file tool, which is distributed with linux can help here. file compares the file contents against a database, and looks for a match. Various file formats use magic numbers in their headers, for instance, every JPEG file starts with FFD8, and ends with FFD9. you may remember that the old DOS executables always start with MZ, which is again a magic number.

share|improve this answer

Most Linux desktops use xdg-open for this behind the scenes. That queries the local xdg-mime XML database, which can identify files by their extensions, as on Windows, or by magic bytes in the files themselves, depending on configuration.

If you want to add support for additional file types, you can do so using xdg-mime. This page documents its XML semantics.

In principle it's also possible to use mailcap for this (with run-mailcap), which does only look at extensions, but I haven't seen a desktop environment that does that in a very long time.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .