Which extension to use for text files? (Unix/Linux)

filesfilesystemstext;

I noticed that I can read text files without an extension .txt just fine. How come? Should I save these files with or without the .txt extension?

Also, what about .ini files? I usually use them like this: config.ini, should I remove the extension here to?

Any general resources on how Linux handles file extensions would be useful.

Best Answer

UNIX/Linux does not have the same early DOS / CP/M heritage that Windows does. So extensions are generally less significant to most UNIX utilities and tools.

I usually use a command-line only environment. Extensions in such an environment under Linux aren't really significant except as a convenience to the operator or user. (I don't have enough experience with KDE or GNOME to know how their filemanagers deal with extensions.)

But such convenience is usually important. If config.ini is really in Microsoft-standard ".ini" format, I'd let the extension stand. Plain old text files usually carry no extension in Linux, but this isn't universal for all programs configuration files. The programmer usually gets to decide that.

I think ".txt" is useful under Linux if you want to emphasize that it's NOT a configuration file or other machine-readable document. However, in source distributions, the convention is to name such files all caps without an extension (i.e. README, INSTALL, COPYING, etc.)

There are some standards and conventions but nothing stopping you from naming anything whatever you want, unless you are sharing things with others.

In Windows, naming a file .exe indicates to the shell (usually explorer.exe) that it's an executable file. UNIX builds this knowledge into the file system's permissions. If the proper x bits (see man chmod) are set, it is recognized as executable by shells and kernel functions (I believe). Beyond this, Linux doesn't care, most shells won't care, and most programs look in the file to find it's "type."

Of course, there's the nice command file which can analyze the file and tell you what it is with a degree of certainty. I believe if it can't match the data in the file with any known type, and if it contains only printable ASCII/Unicode characters, then it assumes its a text file.


@Bruce Ediger below is absolutely correct. There is nothing in the kernel or filesystem level, i.e. Linux itself, enforcing or caring that the contents of a file needs to match up with its name, or the program that is supposed to understand it. This doesn't mean it's not possible to create a shell or launcher utility to do things based on filename.