I need to be able to execute an executable shell script (sh) with a double click. I set the executable flag on the permissions for the file, and yet when I double click on it, it opens in a text editor. I do not have any options in my UI under the files properties menu to use a custom command or anything. It only lists various applications which are installed. I just want it to execute, nothing more. How can I accomplish this?


To run your script by double clicking on its icon, you will need to create a .desktop file for it:

[Desktop Entry]
Name=My script
Comment=Test hello world script

Save the above as a file on your Desktop with a .desktop extension. Change /home/user/yourscript.sh and /home/user/youricon.gif to the paths of your script and whichever icon you want it to have respectively and then you'll be able to launch by double clicking it.

  • I think in Centos 7 shuld be Exec[$e]='/home/user/yourscript.sh' – taliezin Mar 12 '15 at 17:43
  • @taliezin thanks, I'll take your word for it. I don't have access to a RH-derived system to check. – terdon Mar 12 '15 at 23:44
  • Sorry about the late accept, this worked out – Mark W Mar 13 '15 at 19:25
  • The above solution works fine for me without adding the Exec[$e] on Centos 7. Perhaps a later revision changed what is required. – Heather92065 Mar 31 '17 at 17:03

Its actually very simple to do that. Just go to your Nautilus files preferences and click on 'Behavior' tab. Under the 'Executable Text Files' check 'Ask each time' or 'Run executable text files when they are opened'. Please look at the screenshot for reference.

Files Preferences

  • This is actually the correct answer. You don't need a .desktop file. – user64141 May 25 at 3:51

This involves using dconf-editor (sudo yum install dconf-editor):

Open dconf-editor, and navigate to the /org/gnome/nautilus/preferences menu.

Under "executable-text-activation", change "Use default value" to OFF, and "Custom value" to 'launch'.

You can then exit dconf-editor.

At this point, double-clicking on an icon which is a script, or a symbolic link to a script, will execute it, rather than opening up the file with gedit, which is what my system was doing.

So after changing the above preference, all I had to do is:

$ cd $HOME/Desktop

$ ln -s $HOME/bin/myscript.sh MyScript

and that's that.

(My system is GNOME Version 3.1.2 running on CentOs 7)

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.