Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What could cause file(1) command to output application/msword application/msword (yes, twice in a row) as the mime type for some of the .doc files? Normally it prints just application/msword.

If run without --mime it prints Microsoft Office Document on both 'normal' and 'special' .doc files.

share|improve this question
    
Actually not all of the files are .doc, it appears that some of them are .xls, for which I get application/msword (once) and for .docs I get it twice. –  alex May 23 '11 at 19:08
    
Strange indeed. What is the exact file invocation (with exact file names)? What is the exact file version (version number, distribution, …)? –  Gilles May 23 '11 at 21:55
    
@Gilles: file-4.17-15.el5_3.1.x86_64 on CentOS 5.5 Final. Command line is like this: file -bi /path/to/file/<md5-like-string>, where the filename doesn't have any suffix. –  alex May 24 '11 at 7:20
    
Is it sending both responses on the same stream? –  symcbean Sep 22 '11 at 11:39
    
What does your /usr/share/misc/magic file (or equivalent) look like? What happens when you use the -k option? –  barrycarter Oct 19 '11 at 1:26

1 Answer 1

From the magic(5) man page:

Some file formats contain additional information which is to be printed along with the file type or need additional tests to determine the true file type. These additional tests are introduced by one or more > characters preceding the offset. The number of > on the line indicates the level of the test; a line with no > at the beginning is considered to be at level 0. Tests are arranged in a tree-like hierarchy: If a the test on a line at level n succeeds, all following tests at level n+1 are performed, and the messages printed if the tests succeed, untile a line with level n (or less) appears. For more complex files, one can use empty messages to get just the "if/then" effect, in the following way:

       0      string   MZ
       >0x18  leshort  <0x40   MS-DOS executable
       >0x18  leshort  >0x3f   extended PC executable (e.g., MS Windows)

On our Scientific Linux 5.5 system, /usr/share/file/magic.mime lines 836..838 look like this:

0       string  \320\317\021\340\241\261\032\341        application/msword
>546    string  bjbj                    application/msword
>546    string  jbjb                    application/msword

So, once the first line matches, file will check for bjbj and jbjb at the given location, printing an additional application/msword string on success.

Note: if you want to fix that file, you have to remove, rename, or regenerate (with file -C) the binary version, /usr/share/file/magic.mime.mgc, since file prefers that one to the text version.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.