Are you allowed to come up with any desired file extension (for Unix, Linux, Windows)

file extensionfile format

I want to create a file called "message" that contains text only. How does the system know what program to use to read it if I decide to call it:

  • message.txt?
  • message.dat?
  • message.enc?
  • message.cpz?
  • message.asdfasdf?
  • message.abcdefghijklmnopqrstuvwxyz?
  • message.this_is_so_random?
  • or just 'message' with no extension?

I was wondering this for text-only files, but what about files that contain video and audio?

Best Answer

Linux (/Ubuntu) does not depend on the file extension as Windows does. Every file has a part inside it where it identifies itself as to what it is. To show what a random file is we have the command file. Some random examples:

$ file *
Aptana Studio 3:       directory
Create ubuntu live cd: ASCII English text, with very long lines
1.txt:      empty
gedit_open: Bourne-Again shell script text executable

You can also find the mimetype from command-line:

$ file --mime-type -b 1.txt 
application/x-empty
$ file --mime-type -b gedit_open 
text/x-shellscript

We do have a ~/.local/share/applications/mimeapps.list where you can associate programs to the extension. You can set those with the open with inside properties of a file when using Nautilus or by using command-line (see https://askubuntu.com/questions/46020/how-to-add-a-mime-type-with-a-project-created-in-quickly )

So basically you can do whatever you want with a filename but I would suggest to use for instance .conf for it if it contains configuration settings but this is strictly for human understanding. Since you generally need to execute a file for it to be associated with the program that is set for this mimetype and you generally set the permission to non executable it is not a issue.

Related Question