xdg-mime is part of a collection of scripts called xdg-utils, "a set of common interfaces for desktop environments (DE)". In your particular case, I'll just quote MestreLion's comment from here:
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"
As to the internal mechanics of xdg-utils... They're just shell scripts checking for a DE and, IF found, calling that particular DE's file tools to perform a certain task. In GNOME xdg-open calls gvfs-open and xdg-mime calls gvfs-info (both gvfs-* tools giving preference to judgement by file extension). In your case, no DE is found so xdg-mime falls back to
file to get information about the file content type. Here is the code section from xdg-mime for "generic" DE (or rather unknown):
DEBUG 1 "Running file -i \"$1\""
/usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
if [ $? -eq 0 ]; then
Though it is true
file results are not always 100% accurate, there's not much you can do about that (it's still the best tool for this job IMO). However, if you want to determine the mime types based only on files extensions (a la windows) you could write your own script. Here is a simple python example:
if len(sys.argv) != 2:
print ("Usage: ./pymime filename")
testfile = os.path.abspath(sys.argv)
mt = mimetypes.guess_type(testfile, strict=True)
print ("%s" % mt)
Name it pymime and run: