How does Linux decide which NTFS text files are executable, and can it be customised?

an incubator for software projects


Moderator: Forum moderators

Post Reply
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

How does Linux decide which NTFS text files are executable, and can it be customised?

Post by miltonx »

Text files on ntfs partitions have no permission attributes, so linux by defaults sees some of them as executable, such as .sh files. But sometimes this can be annoying, eg. I often edit .yaml config files, but Linux sees them as executable too. When I double click a .yaml, it gets executed insdead of being opened by text editor.

I'm doing this on debian, so it may behave differently from puppy. But anyway, there must be some mechanism by which the system tells which text files are executable. Can it be modified?

williams2
Posts: 1062
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 305 times

Re: How does Linux decide which NTFS text files are executable, and can it be customised?

Post by williams2 »

iles on ntfs partitions have no permission attributes, so linux by defaults sees some of them as executable

ntfs file systems that are mounted using the ntfs-3g driver do not have permissions or ownership, so the permissions and ownerships are set for all files and directories when the file system is mounted.

You can not change the permissions of individual files.

You can change the permissions for all of the files and dirs by remounting the file system, specifying the permissions using umask.You can search for information using Google or Duckuckgo, etc.

https://en.wikipedia.org/wiki/Umask

I mount the ntfs file system on my sda4 like this:

Code: Select all

ntfs-3g /dev/sda4 /mnt/home -o umask=0022,no_def_opts,noatime,rw,silent

I could remount the file system with different permissions like this:

Code: Select all

ntfs-3g /dev/sda4 /mnt/home -o umask=0000,no_def_opts,noatime,rw,silent[

AFAIK, I think you can remount just specifying the options that actually change, like this:

Code: Select all

ntfs-3g /dev/sda4 /mnt/home -o remount,umask=0000

There is a new driver, ntfs3, in kernels 5.15 and newer, that is supposed to support linux permissions and ownerships. I have not tried it.

Remounting a file systems that is an aufs layer may or may not work.

Shell scripts with text commands in the file are not really executable.
Shell scripts usually has as the first line something like this:
#!/bin/sh

Text files that are marked as executable will usually be executed by /bin/sh by default.

If you want a text file set as executable to not execute when clicked or executed as a shell command, you could put the shell command exit as the first line of the text file.

If you put exec geany "$0" as the first line of a text file, it will open in geany as an editable text file, when clicked.

A shell script can be executed like this sh myscript whether the executable bit is set or not.

miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Re: How does Linux decide which NTFS text files are executable, and can it be customised?

Post by miltonx »

williams2 wrote: Fri Sep 16, 2022 6:59 am

You can change the permissions for all of the files and dirs by remounting the file system, specifying the permissions using umask.You can search for information using Google or Duckuckgo, etc.

I would still like the .sh files and other general text files with shebang to be naturally executable on ntfs. Just some other files such as .yaml can be annoying when it is treated as executable script. So this blanket approach does not solve my problem.

However, by further testing, I realized that my problem stems from the specific file manager rather than the linux system.

I tested pcmanfm and rox-filer on debian. Although the same .yaml file on ntfs is by default executable, rox-filers simples ignores that and opens it with geany, whereas pcmanfm tries to run it as a script.

So my question should be whether this is configurable on pcmanfm.

Post Reply

Return to “Development”