I recently learned that file extensions (at least for plain text) in a Unix-like environment generally don't have meaning. Whether a bash script has a .sh,.log,.txt, or .hgfjgfdjgd, it can still run if you make it executable with chmod +x scriptname.

Upon figuring this out, I've slowly been starting the (perhaps bad) practice of the not using file extensions anymore. Any general text file or script I write nowadays doesn't have an extension, and everything still works just like before.

The one and only advantage I can think of for using file extensions in this situation is organization, for both yourself and others (ie. people recognize a .sh file as being a script). But other than that, they just seem useless at this point, as they add extra "complexity" for no reason.

Is what I'm doing a bad practice? Are files without extensions generally frowned upon? What other uses do extensions have for plain text files that I'm not seeing?

  • 4
    This doesn't appear to be about a conceptual programming issue and is move of a naming convention issue. As such, I believe it's off-topic for Programmers. I don't know the other SE sites well enough to suggest amongst them. In general, file extensions provide semantic meaning about what to expect in the file. So I think your new-found habit is a pretty bad one. – user245693 Sep 18 '14 at 16:16
  • 3
    This question appears to be off-topic because it is about file naming conventions. – user245693 Sep 18 '14 at 16:20
  • For data files, it often matters (see Basile's answer). For executables, I rarely see anyone use file extensions (they just make the name longer to type). – Michael Kohne Sep 18 '14 at 17:01

File system extensions don't have any meaning inside the Linux kernel.

However, several applications (web servers, compilers, editors, linkers) tend to use file extension on purpose. You could get the gcc compiler to accept some file name source-file (or even bizarre.o or strange.sh) as some C source file, but you'll need some tricks (the -x option). Also, you will unpleasantly surprise other people.

BTW you could also name all your files as 0001, 0002, etc... but this is not very user friendly.


I use file extensions for a number of reasons. In many cases, this is to save me working around the issues resulting from not using an extension. There are few cases were not using an extension provides an advantage, mainly when running a program.

In Unix/Linux file extensions don't have meaning when it comes to executing a file. This is controlled by the executable bit. The interpreter for scripting languages is specified in the first line using a bang path such as #!/bin/bash.

For executable files in standard directories, it is standard practice to omit the extension. However, it is also common to use extensions for locally written scripts. This is helpful when searching for an example or common practice in a particular scripting language.

For non-executable files the extension provides valuable type information both user and programs that read them. Web servers use the file extension extensively in determining the file type, and thus what headers to apply. Compilers and programmers rely on the extensions to determine the file types.

Some tools will use magic files to determine the file type based on the file contents. Many file types contain magic values at known locations, and these can be used to reliably guess the file type in many cases. Other tools will just open a file assuming it is an appropriate file. This allows you to play text files or text edit pictures, although neither are recommended.

Within classifications of files there are often incompatible types which are normally indicated by the extension:

  • Pictures: bmp, jpeg, gif, png, tiff...
  • Videos: mpg, rm, flv, wmv...
  • Sound: mp3, ogg, wav...
  • Documents: html, txt, pdf, rtf, doc...

While some tools can handle multiple formats, others will fail with one or more types. Omitting the file extension will likely lead you to use the wrong tool to open some files.

There are also cases where there are multiple related files are differentiated by the extension. For example a program foobar written in c may result from the files foobar.c, foobar.h, and foobar.o.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.