4

When I create a file without file extension and put some text like this in it:

//this file is just a simple text file
and you are reading it

Ubuntu think it's C source code file and change the icon to the C file. When I right click on the file and click properties, It shows:

type: C source code (text/x-csrc)

I've noticed every time I start a text file content with // Ubuntu think it's not a text file anymore.

Nautilus simple text file as C source code file

When I run file command on the terminal it shows:

textfile: ASCII text

This problem can fix by adding .txt file extension to the filename but I don't want to use .txt on the file extension.

There is another thing. When I hit enter and then put // in the text file it thinks it's a text file and it's not a C source code file.

Nautilus simple text file

How can I fix it?

ICE
  • 2,065
  • What is wrong with that? The system tried to guess what type pf a text file was that. The guess was maybe wrong, but it does not affect anything. – Pilot6 Jan 05 '17 at 19:18
  • @Pilot6 I know it doesn't affect anything but I have many text files with that format. Every time I see them in Nautilus I must open them to see if they are actuality C file or Not :( – ICE Jan 05 '17 at 19:28
  • Possibly related: Files starting with a comment have the wrong mime type. It looks like you can trace this (or similar) behavior right down to the freedesktop shared-mime-database – steeldriver Jan 05 '17 at 21:10
  • @steeldriver It seems the first link is a little bit different but the second link is the same. It seems I must open and edit every text file I have. – ICE Jan 05 '17 at 22:56
  • @ICE How come you don't want to use the .txt extension? That makes more sense to me than editing all your files and removing the // – Andy Jan 07 '17 at 12:09
  • 1
    @andy Because I renamed all of my .txt files before. I think the best solution is what you are saying. using .txt extension. Wrong guess is more than //. even if I start a text file wit if Ubuntu changes the icon to the audio file! – ICE Jan 07 '17 at 13:33

1 Answers1

7

In C (and many programming languages) we use "//" to inform compiler to ignore lines starting with that.

I tested myself and made a document like you, and it's treated like c source file too. I even made a document with "/* */" comments, which is also treated as c source file.

These are common for c so you shouldn't be surprised system believes it's source file.

Solution: don't start text files like that I guess.

Hochopepa
  • 166
  • 1
    I think that's clearly a bug that should be reported in Launchpad. It's insane to assume C if "//" is found. Why not C++? Or JavaScript? – juzzlin Jan 05 '17 at 18:56
  • Maybe it's first language to pass "initial syntax check" while checking the file, who knows? It's a bit funny, but I agree. It' a bug. – Hochopepa Jan 05 '17 at 19:03