Yes, I know that I can make a file non executable by setting appropriate permission bits on that file. What I want to do is, making all the files with a certain extension non-executable, So that Nautilus will prompt. The specific extension which I have in my mind is .txt.

In summary, How to instruct Ubuntu not to execute any files with .txt extension?

Note: There is a similar feature in Windows 7 as far as I know.


No file has executable permissions when created unless you changed the default umask settings yourself. You always need to set executable permissions yourself.

What I want to do is, making all the files with a certain extension non-executable, So that Nautilus will prompt.

Nautilus has some options though (in preferences, behaviour, middle set of options):

enter image description here

What this does is check the file you click and check what the file is (by checking the shebang line or the 1st byte of the file) to see if it is an executable and offer to either execute, view or ask what to do with the file you clicked. Text files that have contain text (and not a shebang and/or code) will always open instead of getting executed.

Mind you: this is NOT based on extensions. Extensions are (/should be!) visual aids for us humans; not a way for programs to identify files (an MP3 named music.txt is still an MP3 and not a text file).

  • 1
    I have a feeling this was tried already as the person who asked the question has 20k+ rep and is probably familiar enough with Ubuntu to try it. – mbiber Oct 25 '14 at 14:32
  • 1
    @mbiber - You should not assume anything . Just because a user has a high rep does not make him or her all knowing. – Panther Oct 25 '14 at 16:35
  • 1
    You can not do exactly what you want, set permissions of a file or new file *.txt based on the extension. You can set or change umask as explained by Rinzwind, but it also depends on other variables such as the file system (ext4 vs FAT vs NTFS). – Panther Oct 25 '14 at 16:38
  • 2
    Also, unlike windows, Linux does not use file extensions to identify files. Linux uses magic - see askubuntu.com/questions/108600/… – Panther Oct 25 '14 at 16:40
  • Rinzwind, I know this. Without this, no file can be executed from nautilus, this behavior was since 13.04 or later (idk exactly). But still waiting if anyone can suggest – Anwar Oct 25 '14 at 19:26

Ubuntu offers to execute file only if it has execute permissions. So remove execute permission from all .txt files and you're all set.

find /home/yourname -type f -iname "*.txt" -exec chmod -x {} \;

Maybe also do the right click 'open with' and change default program to your editor.

  • 2
    If I read it correctly I would assume he wants this behaviour also for files created in the future. – Rinzwind Oct 25 '14 at 14:20
  • OK, so add it to crontab. Or look up what is executed while transferring/opening files and change source code. – mbiber Oct 25 '14 at 14:30
  • 1
    Changing the umask setting from bashrc just for txt files would be easier. But then again: I still doubt any txt file gets execute persmissions after creating it. rw yes. But x? Not from a default installation. – Rinzwind Oct 25 '14 at 14:43
  • Thank you, but I said in the question that I can make files non-executable with chmodding. @Rinzwind was right in the first comment – Anwar Oct 25 '14 at 19:24
  • To accomplish this afaik you have to look into the source code. I am sorry I can't be more helpful. – mbiber Oct 25 '14 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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