Also known as libmagic, file command
standard Unix program
1. If file does not exist, cannot be read, or its file status could not be determined, the output shall indicate that the file was processed, but that its type could not be determined. 2. If the file is not a regular file, its file type shall be identified. The file types directory, FIFO, socket, block special, and character special shall be identified as such. Other implementation-defined file types may also be identified. If file is a symbolic link, by default the link shall be resolved and file shall test the type of file referenced by the symbolic link. (See the -h and -i options below.) 5. The file utility shall examine file and make a guess at identifying its contents based on context-sensitive default system tests. (The answer is not guaranteed to be correct.) If file does not exist, cannot be read, or its file status could not be determined, the output shall indicate that the file was processed, but that its type could not be determined. Provide a default value for the internationalization variables that are unset or null. (See XBD Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) If set to a non-empty string value, override the values of all the other internationalization variables. Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files). Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. [XSI) ] ![[Option Start]]( Determine the location of message catalogs for the processing of LC MESSAGES. ![[Option End]]( 6. Position-sensitive default system tests and context-sensitive default system tests are not applied if the -M option is specified unless the -d option is also specified. If the file named by the file operand does not exist, cannot be read, or the type of the file named by the file operand cannot be determined, this shall not be considered an error that affects the exit status. Each line shall be composed of the following four -separated fields. (Implementations may allow any combination of one or more white-space characters other than to act as field separators.) The type of the value in the file to be tested. The type shall consist of the type specification characters d, s, and u, specifying signed decimal, string, and unsigned decimal, respectively. The type string shall be interpreted as the bytes from the file starting at the specified offset and including the same number of bytes specified by the value field. If insufficient bytes remain in the file past the offset to match the value field, the test shall fail. The default number of bytes represented by the type specifiers d, f, and u shall correspond to their respective C-language types as follows. If the system claims conformance to the C-Language Development Utilities option, those specifiers shall correspond to the default sizes used in the c99 utility. Otherwise, the default sizes shall be implementation-defined. Octal sequences that can be used to represent characters with specific coded values. An octal sequence shall consist of a followed by the longest sequence of one, two, or three octal-digit characters (01234567). The test shall succeed if the value from the file equals the value field. The test shall succeed if the value from the file is less than the value field. The test shall succeed if the value from the file is greater than the value field. The test shall succeed if all of the set bits in the value field are set in the value from the file. The test shall succeed if at least one of the set bits in the value field is not set in the value from the file. The message to be printed if the test succeeds. The message shall be interpreted using the notation for the printf formatting specificat
Excerpt from a page describing this subject · 26,437 chars · not written by Vinony
Phone: Do not even think of telephoning me about this program. Send cash first! The major changes for 5.x are CDF file parsing, indirect magic, name/use (recursion) and overhaul in mime and ascii encoding handling. The prime contributor to Release 3.8 was Guy Harris, who put in megachanges including byte-order independence. This release has compiled in numerous environments; see PORTING for a list and problems. In addition, the /etc/magic file is built from a subdirectory for easier(?) maintenance. I will act as a clearinghouse for magic numbers assigned to all sorts of data files that are in reasonable circulation. Send your magic numbers, in magic(5) format please, to the maintainer, Christos Zoulas. COPYING - read this first. README - read this second (you are currently reading this file). INSTALL - read on how to install src/apprentice.c - parses /etc/magic to learn magic src/apptype.c - used for OS/2 specific application type magic src/ascmagic.c - third & last set of tests, based on hardwired assumptions. src/asctime r.c - replacement for OS's that don't have it. src/asprintf.c - replacement for OS's that don't have it. src/buffer.c - buffer handling functions. src/cdf.[ch] - parser for Microsoft Compound Document Files src/cdf time.c - time converter for CDF. src/compress.c - handles decompressing files to look inside. src/ctime r.c - replacement for OS's that don't have it. src/der.[ch] - parser for Distinguished Encoding Rules src/dprintf.c - replacement for OS's that don't have it. src/elfclass.h - common code for elf 32/64. src/encoding.c - handles unicode encodings src/file.c - the main program src/file.h - header file src/file opts.h - list of options src/fmtcheck.c - replacement for OS's that don't have it. src/fsmagic.c - first set of tests the program runs, based on filesystem info src/funcs.c - utilility functions src/getline.c - replacement for OS's that don't have it. src/getopt long.c - replacement for OS's that don't have it. src/gmtime r.c - replacement for OS's that don't have it. src/is csv.c - knows about Comma Separated Value file format (RFC 4180). src/is json.c - knows about JavaScript Object Notation format (RFC 8259). src/is simh.c - knows about SIMH tape file format. src/is tar.c, tar.h - knows about Tape ARchive format (courtesy John Gilmore). src/localtime r.c - replacement for OS's that don't have it. src/magic.h.in - source file for magic.h src/mygetopt.h - replacement for OS's that don't have it. src/magic.c - the libmagic api src/names.h - header file for ascmagic.c src/pread.c - replacement for OS's that don't have it. src/print.c - print results, errors, warnings. src/readcdf.c - CDF wrapper. src/readelf.[ch] - Stand-alone elf parsing code. src/softmagic.c - 2nd set of tests, based on /etc/magic src/swap.h - byte swapping src/swap.c - byte swapping src/mygetopt.h - replacement for OS's that don't have it. src/strcasestr.c - replacement for OS's that don't have it. src/strlcat.c - replacement for OS's that don't have it. src/strlcpy.c - replacement for OS's that don't have it. src/strndup.c - replacement for OS's that don't have it. src/tar.h - tar file definitions src/vasprintf.c - for systems that don't have it. doc/file.man - man page for the command doc/magic.man - man page for the magic file, courtesy Guy Harris. Install as magic.4 on USG and magic.5 on V7 or Berkeley; cf Makefile. Parts of this software were developed at SoftQuad Inc., developers of SGML/HTML/XML publishing software, in Toronto, Canada. SoftQuad was swallowed up by Corel in 2002 and does not exist any longer.
Excerpt from the source-code README · 7,331 chars · not written by Vinony
via Wikidata · CC0
via Wikidata sitelinks · CC0
Discovered by embedding cosine similarity (sentence-transformers MiniLM, 384-dim).