Update: For monks who are unfamiliar with the Unix file command, it is a utility that examines the contents of a file and reports the file type. It works on both binary and text files, using magic numbers and/or string tables to make its determination. Here's an example:
% file /usr/bin/perl /usr/bin/perl: ELF 32-bit LSB executable, Intel 80386, version 1, dyna +mically linked (uses shared libs), stripped

I tried running file on a few of my C source files, and got back 'C program text'. So file can figure out when an ASCII file consists of C code.

Looking at the manpage for file (on RedHat), I see:

If an argument appears to be an ASCII file, file attempts to guess its language. The language tests look for par­ ticular strings (cf names.h) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a troff(1) input file, just as the keyword struct indicates a C pro­ gram. These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some miscellany (such as tar(1) archives) and determine whether an unknown file should be labelled as `ascii text' or `data'.
Two observations: file guesses on the contents of an ASCII file by examining the first few blocks of the file, and the files you tested this on happen not to contain the strings that file is looking for.

I'm not sure what the best solution is. The file extensions will certainly be useful, as others have suggested.


In reply to Re: file type by chipmunk
in thread file type by ashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.