Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am creating a new file either by using

in terminal: touch newfilename.someext

or

in nautilus: File > Create New Document > Empty Document

The file takes on the type "plain text document" and gets associated with the default text-editor. How can I turn-off these 2 actions?

The .somext is a new/unknown extension and I expect the system to show it as an unknown file type.

Edited August 10 2012:
I noticed that if you have a non-printing binary character in the file, then it will show as type "Unknown".

share|improve this question
2  
What do you mean non-printing characters? Returns, spaces and tabs? –  Peachy Aug 10 '12 at 8:51
1  
@msPeachy I meant binary characters like what Andrey (in the accepted answer) explains. –  Sri Aug 11 '12 at 11:40
add comment

2 Answers

up vote 6 down vote accepted
+50

Your question is all about MIME types.

MIME type is resolved not only by file extension (glob patterns), but also by file contents (magic rules).

See http://library.gnome.org/admin/system-admin-guide/stable/mimetypes-modifying.html.en#-note-id301200:

When no glob patterns or magic rules match a file, then it is resolved to the MIME type text/plain if it contains textual data or application/octet-stream for binary data. If the file is empty, then it defaults to text/plain.

So exactly as you noted, file with unknown extension is resolved to text/plain, but if it contains binary data, it is resolved to application/octet-stream, which is shown as "Unknown" (if you are curious why, search for "application/octet-stream" in /usr/share/mime/packages/freedesktop.org.xml).

If you need to register new extension and associate some application with it, you should first register new MIME type, associated with desired extension, and then associate some application with this new MIME type. The following links explain this:

If you don't need to register new extension, I don't see any reason to change the default behavior (resolve text data to text/plain). It's natural.

share|improve this answer
    
My reason may sound stupid (or paranoid), but I am worried about the "executable permission" for text files. A garbage (read malware) file that gets identified as text file could get executed by mistake (or intention), if I (or someone less careful) double click on it assuming it to be a text file. If it was shown as "unknown" one would at least not double click it. So, IMHO the natural behavior should be to mark it unknown. –  Sri Aug 11 '12 at 11:32
1  
Did you consider setting "view" as a default action for executable files in nautilus? Take a look here: askubuntu.com/q/143963/82364. –  Andrey Aug 12 '12 at 19:21
    
Yes. It is one of the things I do at every Ubuntu install. I go into Nautilus -> Edit -> Preferences -> Behavior and set the "Executable Text Files" to "Ask each time". (I keep installing Ubuntu in computers of people in my circle). My anxiety is for the new Ubuntu/Linux embracer. –  Sri Aug 13 '12 at 12:08
add comment

You can choose not to open those extensions, by not associating any application to them.

If you use Ubuntu Tweak, they have a nice part on System/File_Type_Manager, where you can manage all file extensions, and what applications to open them.

Ubuntu tweak can be installed by going to their homepage and hitting the Download button and opening the file with Software Center

share|improve this answer
    
I want to avoid using 3rd party extensions as far as possible. –  Sri Aug 11 '12 at 11:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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