I installed a new file type to share MIME database. But xdg-mime query filetype cannot tell the new type. This problem only happens on my own Linux OS which does not use GNOME or KDE as its desktop. On Ubuntu, the same process works well.

I found that xdg-mime query filetype uses "file -i filename" under the hood on my OS but uses gnomevfs on Ubuntu.

Here are my steps:

wrote a xml file for my new file type my_file.xml

xdg-mime install my_file.xml

xdg-mime query filetype <name of file to query> .... no output :-(

I checked /usr/share/mime/applications and found the xml entry generated by update-mime-database there. And the C API g_file_info_get_content_type() can get the proper mime type.

So it seems the shared-mime-info has been updated successfully. But the "file" command still fails, why?

If you dont have any desktop enviroment, you should not use xdg-mime (or any other xdg tool). xdg is meant to provide interoperability between different desktop enviroments, but not when there is none. Think of xdg as desktop-agnostic, but not "desktop-atheist"
–
MestreLionJul 4 '11 at 4:05

@Giles: xdg-mime uses Freedesktop database when it is avaliable and and there is a DE (like Gnome or KDE) installed to actually read the database. Since OP has no DE, xdg-mime has no tools to query its own database, and falls back to file
–
MestreLionJul 1 '11 at 18:35

After installing this package, xdg-mime (tested version 1.1.0 rc1 on Arch Linux) should now detect that mimeinfo (which does use the XDG shared mime info database) is available, and use that instead of falling back on file -i.