Ubuntu – Ubuntu think the text file is “C source code” file


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?

Best Answer

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.