0
Is there any alternative to the file
command that can be used to identify plaintext file types that don't have a magic number? E.g. something I can give a file to that contains JSON and I'll get back an answer like "JSON" instead of "ASCII text".
Failing that, are there any alternative magic files available that can make the file
command behave like this?
Plain-text files have no distinguishable identifiers or structure, because they're PLAIN TEXT. :) – Ƭᴇcʜιᴇ007 – 2014-03-27T19:41:39.603
1@techie007, linux has binary files and plain text files. For plain text files, there are various formats that they can hold (xml, html) and patterns that are discernible for scripts (perl, python, bash, etc). IDEs use these patterns to color code the lines and keywords in the files. The file command can tell some differences (it will return "POSIX shell script text executable" for a shell script, which is still technically a plain text file). – MaQleod – 2014-03-27T19:49:31.627
3@maQleod There's no way to identify a file type that has no recognizable structure (aka "format"), regardless of OS. Since plain text files inherently have no defined structure or format, they can't be recognized as such. At best all you can do is rule out all other known structures and then assume the file is plain text. – Ƭᴇcʜιᴇ007 – 2014-03-27T19:57:20.567
I know of no generally superior replacement for
file
nor better source of magic files. But, since there are so many types of files for whichfile
is either unreliable or insufficiently detailed, I often end up cobbling together custom python scripts for the purpose. – John1024 – 2014-03-28T01:34:19.693This raises the question why would you like to do this? What exactly is wrong with
file
? – Sami Laine – 2014-03-28T06:07:35.353