File extensions in Linux
Try not to confuse third-party software!
Unlike Windows, Linux does not care about the extension of your files. It looks into the file contents and will figure it out by its own. In other words, Linux is extension agnostic. If you are interested to test it for yourself, use
file command and give it your file name as an argument. For example, imagine you have a PDF file named
tutorial.pdf, you can find its type by typing
$ file tutorial.pdf on the terminal. Look at below picture. As you see the file type is PDF document and even when I changed it to
Tutorial.txt, its type is still PDF document.
So, by changing a file extension, you can not fool the OS. It still knows what file type it is.
The file type does not change with changing the extension
However, you might fool third-party software. For example, if you have a text file named
book.txt and change its extension to
book.pdf , its icon changes because your system has assigned files with
One file with two extensions
But if you try to open the file with PDF reader, you will get an error message. Look at the error message I got when I was trying to open
book.pdf with my PDF reader. As you see below, it says, the file type plain text document (text/plain) is not supported.
Error message when trying to open a file with wrong extension
You might argue that extensions are important to Linux. The answer is extensions are not important to Linux, but they are important to Gnome, which is your desktop environment for Unix-like operating systems. Desktop environments have their own mechanisms that rely on file extensions to determine which applications to call to open a file. It makes things very convenient for the user.
Although Linux is extension agnostic, it does not mean extensions are useless. They are quite useful conveying information about the file type. Linux doesn’t care, but you as a user might care to learn what file does without looking at its content. For example, the moment you see
setup.txt, you can quickly distinguish which one is executable and which one is just a guide.
This article was originally published by Saeed Mohajeryami on medium.