Test for a particular file format

file formatfile-commandfiles

This is a followup to Normal looking text file, detected by file as ASCII Pascal program text

It seems file can't be trusted all the time.

It seems possible that a particular file may be detected as having both encoding/format1 and encoding/format2. file tells me it's encoding/format1, but I need to check, whether it also satisfies the constraints of encoding/format2.

  • Is there a way to do that?
  • Is there a way I can ask "Check if this file follows the rules of
    ASCII English Text (or some other encoding)" and the answer will be
    "yes" or "no"?

Best Answer

Maybe you can use the --keep-going (-k) option of file. It writes out more matching formats.

Related man page description of this option:

Don't stop at the first match, keep going. Subsequent matches will be have the string ‘\012- ’ prepended. (If you want a newline, see the -r option.) The magic pattern with the highest strength (see the -l option) comes first.