*Technically,* they don’t *do* anything. It’s just a part of a file name, and in some file systems there aren’t any extensions at all. I don’t know of a single FS that actually uses extensions on Linux, for example, and I’m fairly sure macOS doesn’t have them either. This, of course, doesn’t prevent these systems from using PDF files, for example, as they simply “know” that “that thing after the dot is maybe telling us what kind of file that is”. But they also heavily use files without extensions, for example most executable files on Linux, because Linux file systems has special file attributes to indicate that a file is exectuable.
On Windows, these are leftovers from DOS where a file name could only consist of a name between 1 and 8 (sic!) characters long and extension between 0 and 3 characters long, known as the 8.3 scheme. These restrictions have been lifted somewhere around Windows 95, but the idea of an extension remained, as it proved to be useful for indicating file types.
Therefore, we have a lot of file extensions now that are unofficially reserved for various file types. It’s not like they *must* be named like that, but it’s very convenient when they are, because it makes figuring out a lot of stuff about a file much easier. Any sensible OS has a set of properties registered for known file types (and any app can register their own types), and they determine a lot of useful data, such as:
1. What icon to display. Some files (like EXE) can actually have an icon inside, but in most cases it’s more useful to have an icon defined once and for all (like PDF).
2. What context actions are available. For example, when you right-click a PDF file, you can print it right away without opening it because your file manager knows a PDF can be printed.
3. What app (or apps) to open it with. This is configurable, and there may be multiple apps that match, in which case it’s useful to show a list of apps to choose from.
And there are many more applications for them. For example, a web server may know that if a file is named something.html, it should be sent to your browser as-is, but if it’s something.php it should be passed to the PHP interpreter to convert it to HTML first. Or when you’re browsing GitHub, it knows that files ending with MD are MarkDown files and therefore they’re nicely formatted for you instead of forcing you to look at raw MarkDown.
If a file doesn’t have an extension, figuring out what it is becomes a lot harder as, aside from a few specific cases, you can only guess by looking at its content. And it’s some binary garbage in many cases, so you need a hex editor/viewer to do that. An experienced user may guess some common types (like PDF files starting with “%PDF” or EXE files starting with MZ), and there is software that can do such guessing as well, like the `file` command on Linux, but it isn’t 100% reliable and much slower than just looking at the file name.
Latest Answers