'file --mime-type' and 'mimetype' Commands Returning Different Results

Solution 1:

file gets its results from /etc/mime.types.

From there:

application/mathematica-old
application/ms-tnef
application/msaccess                            mdb
application/msword                              doc dot
application/news-message-id
application/news-transmission
application/ocsp-request
application/ocsp-response

mimetype gets it from ...

ENVIRONMENT

   XDG_DATA_HOME
   XDG_DATA_DIRS
       These variables can list base directories to search for data files.
       The shared mime-info will be expected in the "mime" sub directory
       of one of these directories. If these are not set, there will be
       searched for the following directories:

               $HOME/.local/share/mime
               /usr/local/share/mime
               /usr/share/mime

       See also the "XDG Base Directory Specification"
       http://freedesktop.org/Standards/basedir-spec
       <http://freedesktop.org/Standards/basedir-spec>

Worth noting is this part in the man page for mimetype:

For naming switches I followed the manpage of file(1) version 4.02 when possible. They seem to differ completely from the spec in the 'utilities' chapter of IEEE Std 1003.1-2001 (POSIX).

So you might call it a bug against file /etc/mime.types since vnd.ms-excel is more accurate.

Solution 2:

There is a similar difference between the two tools for .deb packages.

It appears that file uses /etc/mime.types and mimetype uses a much complicated mush of more XDG_DATA_DIRS (from man mimetypes):

ENVIRONMENT
       XDG_DATA_HOME
       XDG_DATA_DIRS
           These variables can list base directories to search for data files. The shared mime-info will be expected in the "mime" sub directory of one of these directories. If these are not set,
           there will be searched for the following directories:

                   $HOME/.local/share/mime
                   /usr/local/share/mime
                   /usr/share/mime

           See also the "XDG Base Directory Specification" http://freedesktop.org/Standards/basedir-spec <http://freedesktop.org/Standards/basedir-spec>

FILES
       The base dir for all data files is determined by two environment variables, see "ENVIRONMENT".

       BASE/mime/packages/SOURCE.xml
           All other files are compiled from these source files. To re-compile them use update-mime-database(1).

       BASE/mime/globs
           Compiled information about globs.

       BASE/mime/magic
           Compiled information about magic numbers.

       BASE/mime/MEDIA/SUBTYPE.xml
           Descriptions of a mimetype in multiple languages, used for the "--describe" switch.

Solution 3:

It took me a while to find it, but I was able to install mimetype on debian.

sudo apt-get install libfile-mimeinfo-perl

Now I get application/vnd.ms-excel for a .xls instead of application/msword.