When creating a new text file, should I add a .txt extension to its name?

When I create a new document aimed at containing only plain text, I am not obliged by Ubuntu to add a .txt extension to its name. It works indeed very well: gedit opens it without problem, understanding very well that it is only text.

The only two pro arguments I have found from now on for adding an extension are 1/ interoperability with Windows systems and 2/ avoiding confusion with folders having the same name. Nevertheless those two arguments do not convince me at all. As a consequence, should I keep the reflex of adding an extension to files or not?

Asked By: Agmenor


If you use linux dosent matter.Extensions are meaningless add it if you like..But if you want to view that file in windows, extension is must else you cant view the file. while keeping a well-known extension makes for better interoperability, it may also help certain (not very well written) apps behave better.For example, a mail client might choose a more appropriate MIME type for an attachment.So decide yourself.

Answered By: karthick87

It’s completely your own decision – don’t let anyone chose for you.

If it’s a ‘reflex’ then there’s no harm in keeping your current habbits. On the other hand it does look cleaner without file extensions…

In my opinion the main case for using the extension is if you’re emailing files to Windows users – whilst they could still open it in Notepad (with File->Open With) they will probably confused if you leave it off.

Answered By: 8128

If you want to learn more about how Linux identifies filetypes and why extensions are useless for that purpose, take a look at the file command man page

man file

It’s a kind of magic 🙂

Answered By: zuzust

It doesn’t matter in Linux based systems whether you use a .txt extension or not. In fact, there is no special ‘file extension’ as on Windows – it is just part of the name. MIME types are used to determine the type of the file.

If, however, you wish to share a file with people who are still using Windows, they will have to manually choose to open the text files with notepad unless you use a .txt extension.

There are other compatibility considerations. By default, Notepad will not show new lines correctly because it uses a different line ending to Linux and other Unix like systems. The text editor will show text files in the Windows format correctly but you may need to press backspace twice in order to remove a new line.

Using a text editor called Geany you can convert between line ending types through the Document -> Set Line Endings menu. This may also be possible in the default text editor (Gedit) but I don’t know how to do it.

Personally, I would not use the .txt extension or Windows line endings for daily use but I would convert the files when I needed to share them with Windows users.

Answered By: dv3500ea

In many cases filename extensions are not required on Ubuntu, but often it’s still a good idea to use them. Not only for Windows/Mac compatibility, but also for your own convenience. Imagine if you would remove all file extensions (.html, .jpg, .doc, .ttf, .txt, .py, .conf, etc.); you would have to check the file type all the time, instead of knowing it when reading the file name (of course filenames like README are also obvious).

Answered By: JanC

The extension is optional but depending on your expectations you may wish to use one anyway. For example, Image viewer will fail miserably to open an image with the wrong extension. The thumbnailer will also fail in this example. You can prove this by renaming a JPEG to .GIF or .PNG for example. If you have a file and you aren’t sure what it is you can find out with the command file filename where filename is the file in question. Here’s some example commands and output:

file unity-panel_001.bmp 
unity-panel_001.bmp: PC bitmap, Windows 3.x format, 1280 x 21 x 24
me@zippy-64bit:~/Pictures$ file web-off.png 
web-off.png: PNG image data, 850 x 552, 8-bit/color RGBA, non-interlaced
me@zippy-64bit:~/Pictures$ file XfinityBillShowingLateFee.jpg 
XfinityBillShowingLateFee.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 2480x3437, frames 3
Answered By: Elder Geek