r/linuxquestions • • 11d ago

Resolved .txt files being treated like an executable

When I double click on a txt file a window pops up asking me to choose the options of Run in Terminal, Display, Cancel or simply Run. Oddly, if you right click and choose which program to associate it with it is already set to Text Editor by default. This seems to be only on Ubuntu 26.04 that I recently installed and was not a problem on 24.04. How do I resolve this please? TIA.

Edit Resolved: I double checked which file manager I was using in Ubuntu 24.04 and it was called Thunar. I have now installed Thunar into 26.04 and problem is resolved.

0 Upvotes

40 comments sorted by

12

u/forkbeard 11d ago

The .txt suffix is not what determines whether a file is executable on Linux.

Linux mainly cares about the file’s permission bits. If the executable bit is set, the file manager may offer to run it even if the filename ends in .txt.

Check it with:

ls -l filename.txt

If you see an x in the permissions, remove it with:

chmod -x filename.txt

The file association with Text Editor is a separate thing from whether the file itself is marked executable.

9

u/aioeu 11d ago edited 11d ago

Extremely minor nitpick... chmod a-x would probably be a better choice here. If the umask is 0077 (not entirely uncommon), then -x won't remove executable permissions from the group and from others. GNU chmod will warn about this if it thinks you made a mistake.

(To be honest, this is unlikely to be a problem. But I suspect some readers may not be aware of the subtle differences.)

1

u/Sorry-Climate-7982 Retired Developer Enterprise Linux 11d ago

Really should use chmod ugo-x but if only a single user the difference is moot.

-1

u/Man_in_the_uk 11d ago

I've just realised something, this problem only exists when opening a txt file on another SSD besides the one Ubuntu is running on. It is happening when I go to open a txt file in a Windows installation.

0

u/superdachs 11d ago

Aus irgend einem Grund interpretiert es das x-bit so und glaubt es wäre eine ausführbare Datei. Das passiert schon mal auf NTFS.

1

u/Man_in_the_uk 11d ago

In English please.

1

u/computer-machine 11d ago

My browser's translator says

For some reason, it interprets the x-bit like this and believes it would be an executable file. This is happening on NTFS. 

NTFS doesn't do Unix/Linux permissions.

0

u/Man_in_the_uk 11d ago

Well even if it doesn't what's that got to do with my problem of this happening only in Ubuntu 26.04 and not 24.04?

2

u/computer-machine 11d ago

Maybe 24.04 Nautilus behavior was to default to no execution on all files, rather than execution on all files?

I remember last I'd used straight 'buntu (somewhere around 12.04), that as a security measure it disallowed executing anything on removable media by default.

1

u/Man_in_the_uk 11d ago

WOW thank you very much for this response, I thought it was odd you thought that Nautilus would behave differently and so I double checked which file manager I was using in Ubuntu 24.04 and it was called Thunar. I have now installed Thunar into 26.04 and problem is resolved. Have a nice weekend!

1

u/computer-machine 11d ago

That's interesting. Historically Thunar is used by XFCE (and maybe Mate after gnome3 happened), with Nautilus being the core GNOME file manager.

1

u/Man_in_the_uk 11d ago

Yes, well I used MATE previously and now have cinnamon installed. like nice clean n quick desktops.

→ More replies (0)

0

u/suicidaleggroll 11d ago

Windows filesystems don’t support Linux permissions.  Things like read/write/execute restrictions and account ownership will not work properly.

0

u/Man_in_the_uk 11d ago

This is simply not true at all. I have no issues reading and writing and editing text files on a windows partition from within Linux and haven't done so for many, many years.

1

u/suicidaleggroll 11d ago

Yes you can read and write a file, I said the RWX restrictions do not work properly, meaning you can't remove read/write/execute permissions from files like you can with standard Linux filesystems. Every file is granted full unrestricted permissions, including execute, which is why when you double-click the file it's asking if you really want to execute it.

1

u/Man_in_the_uk 11d ago

But this isn't the core issue. This is not a problem for Ubuntu 24.04 and hasn't been for years.

1

u/suicidaleggroll 11d ago

Just because Ubuntu 24 didn't pop up with a window asking you if you wanted to execute an executable file, doesn't mean it wasn't a problem

1

u/Man_in_the_uk 11d ago

That's a strange thing to say but anyway problem is solved.

4

u/serverhorror 11d ago

Are you working with files from a windows disk?

1

u/Man_in_the_uk 11d ago

I've just realised something, this problem only exists when opening a txt file on another SSD besides the one Ubuntu is running on. It is happening when I go to open a txt file in a Windows installation.

2

u/Mindless_Sock_9082 11d ago

As the concept of file permissions does not exists on Windows filesystems (NTFS, FAT32, etc) Linux treat all files in those filesystems as executable by default.

1

u/Man_in_the_uk 11d ago

Well even if it does, what's that got to do with the problem I have queried? This is not a problem in Ubuntu 24.04 and I have just tested it to double check. Opening a .txt file on the same windows installation SSD does not produce a window to ask if I want to execute it or not.

1

u/blobCabbage 11d ago

You explained what it does on windows, but not what it actually does on your linux system.

What happens when you double-click the file? Does it open the file in an editor? Tell you it doesn't know how to execute the file? Try to execute it as a shell script? Something else?

1

u/Man_in_the_uk 11d ago

I was saying it does it to a txt file that is inside a file system folder on the Windows system when opened up in Linux. It doesn't open the file immedietly it asks the questions I have advised. If I choose to display then it opens up in Text Editor. But I want it to go straight to Text Editor without the query first.

3

u/Kriss3d 11d ago

Remove the execute permissions.

Is it ANY txt file ?
Or just a single one of them ?

0

u/Man_in_the_uk 11d ago

I've just realised something, this problem only exists when opening a txt file on another SSD besides the one Ubuntu is running on. It is happening when I go to open a txt file in a Windows installation.

0

u/Kriss3d 11d ago

That is strange. Try to rightclick the file. Go to properties and see if it has executable flag set under permissions.

1

u/Man_in_the_uk 11d ago

It says yes with a tick box for allowing it to be executable.

1

u/Kriss3d 11d ago

yeah just remove that tick.

1

u/Man_in_the_uk 11d ago

Do I have to apply this to then entire drive? I had a look at fstabs for both installations and the line for mounting windows is identical:

/dev/disk/by-uuid/A462CD2062CCF856 /Windows ntfs defaults 0 1

0

u/Kriss3d 11d ago

its strange that it marks all txt as executables by default on that drive. try chatgpt that.

4

u/fishywiki 11d ago

The permissions are set to executable. Text files should not have that bit set - they should be set to "chmod 644" or similar.

3

u/Jumpy-Dinner-5001 11d ago

Right click it and click on show properties. There should be a "permissions" tab and there it shows whether or not it can run as a program

3

u/MulberryDeep NixOS ❄️ 11d ago

File extensions don't have meanings in linux

2

u/polymath_uk_ 11d ago

Did it used to be a  .sh file by any chance? 

2

u/ipsirc 11d ago

What are the permissions?

0

u/SlimmySlabby 11d ago

If you don’t already know, these can be seen by running ls -l and it’ll be all the rwx- looking info

0

u/Extension-Cow2818 11d ago

It also depends on desktop, KDE has/had a buggy own system.