Unix magic types, also known as magic numbers, or format indicators are a small sequence of bytes at the beginning of a file used to identify the file type.
Here are just a few examples of file magic numbers from Wikipedia:
- Unix scripts:
25 50 44 46
Magic numbers are important to understand if you start writing and reading compressed files. Written compressed files should include your own custom magic number that represents your compression format and doesn’t conflict with any other magic number. You can also read these magic types to determine the format of a compressed file.
These magic numbers and the corresponding file type are generally stored in a file called the magic patterns, also known as the magic database or magic data. This file is used by Unix systems to lookup the file type based off of a file’s magic numbers.
For a more complete list of different magic numbers, check out the Wikipedia entry for a list of file extensions.
To learn more about magic numbers, check out these resources:
- Linux man page for
- List of file signatures on Wikipedia
- Format indicators on Wikipedia
- Working with Magic numbers in Linux