The system uses the extension to indicate the type of the file and the type of operations that can be done on that file. Only a file with a .com, .exe, or .sh extension can be executed, for instance. The .com and .exe files are two forms of binary executable files, whereas the .sh file is a shell script containing, in ASCII format, commands to the operating system. Application programs also use extensions to indicate file types in which they are interested.
For example, Java compilers expect source files to have a .java extension, and the Microsoft Word word processor expects its files to end with a .doc or .docx extension. These extensions are not always required, so a user may specify a file without the extension (to save typing), and the application will look for a file with the given name and the extension it expects. Because these extensions are not supported by the operating system, they can be considered “hints” to the applications that operate on them
file type | usual extension | function |
---|---|---|
executable | exe, com, bin or none | ready-to-run machine language program |
object | obj, o | compiled, machine language, not linked |
source code | c, cc, java, perl, asm | source code in various languages |
batch | bat, sh | commands to the command interpreter |
markup | xml, html, tex | textual data, documents |
word processor | xml, rtf, docx | various word-processor formats |
library | lib, a, so, dll | libraries of routines for programmers |
print or view | gif, pdf, jpg | ASCII or binary file in a format for printing or viewing |
archive | rar, zip, tar | related files grouped into one file, sometimes compressed, for archiving or storage |
multimedia | mpeg, mov, mp3, mp4, avi | binary file containing audio or A/V information |
The UNIX system uses a crude magic number stored at the beginning of some files to indicate roughly the type of the file—executable program, shell script, PDF file, and so on. Not all files have magic numbers, so system features cannot be based solely on this information. UNIX does not record the name of the creating program, either. UNIX does allow file-name-extension hints, but these extensions are neither enforced nor depended on by the operating system; they are meant mostly to aid users in determining what type of contents the file contains. Extensions can be used or ignored by a given application, but that is up to the application’s programmer