0

With file command we can get the file type. File returns a unique answer for each file type. I want to get the total list that file can return for linux & solaris.

For example, I have a partial list of file's return output. Unfortunately I can't see the total list from manual page.

 ASCII C program text  
 ASCII C++ program text  
 ASCII C program text, with CRLF
 ASCII C program text, with very
 ASCII English text   
 ASCII English text, with CRLF line
 ASCII English text, with escape sequences
 ASCII English text, with very long
 ASCII HTML document text  
 ASCII HTML document text, with very
 ASCII Java program text  
 ASCII Java program text, with CRLF,
 ASCII Java program text, with very
 ASCII make commands text  
 ASCII make commands text, with very
 ASCII text    
 ASCII text, with CRLF line terminators
 ASCII text, with escape sequences 
 a /usr/bin/perl script text executable 
 Bourne-Again shell script text executable 
 Bourne shell script text executable 
 core file (Xenix)   
 C++ program text   
 data     
 exported SGML document text  
 extended 669 module data  
 HTML document text   
 ISO-8859 English text   
 Non-ISO extended-ASCII English text  
 Non-ISO extended-ASCII English text, with CRLF
 Non-ISO extended-ASCII English text, with very
 PC bitmap data   
 PC color icon data  
 PC color pointer image data 
 PC icon data   
 PDF document, version 1.2  
 TOC sound file   
 UTF-8 Unicode text, with CRLF line
 XML document text
6
  • Please don't tell me you're trying to parse the output of file like this...
    – Daenyth
    Oct 30, 2010 at 21:08
  • @Daenyth I need the total list that file can return and according to the list I want to verify file type
    – jennifer
    Oct 30, 2010 at 21:12
  • 1
    You need to approach this differently. Whatever it is that you're trying to accomplish, this is the wrong way to go about it. Please be specific about what you're really trying to do. Oct 30, 2010 at 23:01
  • Dennis I return about my question – I need all return answers of file command How can I get this list , what wrong with this question
    – jennifer
    Oct 31, 2010 at 4:56
  • The problem is that the possible output of the file command is buried deep inside the source code, because it contains several modules that are specifically written for, let's say, tarballs. Think about the possible combinations of "with CRLF line terminators". There is probably a huge number of possible types.
    – slhck
    Oct 31, 2010 at 9:09

1 Answer 1

1

You can't get an exhaustive list of output from the file command. The output it generates is determined by the “magic” database, which changes with every upgrade of the program and can be customized by the system administrator and the user. Furthermore, strings returned by file can be built from several pieces, for example text files sometimes get an indication of character encodings, image files can have their size shown, etc.

Under Linux, file -i shows the MIME type (e.g. text/plain, image/jpeg) rather than a string destined for humans. If you were thinking of parsing the output from file, you want file -i. There is an official list of MIME types, but it is not exhaustive: there are plenty of non-standard types out there. Furthermore file -i may complement the MIME type with encoding information (e.g. text/plain charset=utf-8).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .