How can I make my file so that I can double click on it, and it runs. It is a .sh
script, but I also have files that say:
executable (application/x-executable)
in the description of what they are.
I can't run any of these from terminal, or by double clicking.
If possible, I would like a way using either the GUI or a Terminal, but not a combination of the two.
Here is a screenshot of what I see when I right click then go on properties. The file first:
And the shell script here:
NB: I accept that this is a duplicate (I was looking for it, and couldn't find it, so asked + answered it, hoping that I would find it) however, I don't think the question about .desktop files is a duplicate.
There are two ways of making a file executable:
GUI Method:
Go to the permissions tab, then tick the box
Execute: [✓]
Allow executing file as program.Command line method:
Just run:
Note that
chmod
does also have some more advanced options. It accepts three groups of options, represented as--- --- ---
. The first set of---
is User. The second is Group and the last is Other (everyone else).r
stands for Read,w
for Write andx
for eXecute.To allow everyone to read it, but only Group to execute and User to read and write it would be
-rw- rx- r--
. This would be added to the command as:chmod
also can do this in numbers. It is based on binary.So there are these numbers:
Execute by user is
100
. Execute by group is010
. Execute by other is001
Write by user is
200
. Write by group is020
. Write by other is002
.Read by user is
400
. Read by group is040
. Read by other is004
.Then you add these together to get the desired combination.
So to allow everyone to read it, but only Group to execute and User to write it would be
400 + 040 + 004
and010
and200
That adds up to
600 + 050 + 004 = 654
.You could then run the command.
to set it. So to set all permissions you can run:
or
Finally, you can do:
To take all permissions away from everyone.
And:
To add read and write for the user, without affecting any other permissions (e.g. Execute permissions).
This website has a very useful little tool, whereby you can tick the options you want and it gives you the command:
However, not all the possible combinations are sensible to use; the main ones that are used are the following:
755 -
Owner
has all, andGroup
andOther
can read and execute700 -
Owner
has all644 -
Owner
can read and write, andGroup
andOther
can read600 -
Owner
can read and writeAnd, if you're using non-trivial user groups:
775 -
Owner
can read and write, andGroup
andOther
can read770 -
Owner
andGroup
have all, andOther
can read and execute750 -
Owner
has all, andGroup
can read and execute664 -
Owner
andGroup
can read and write, andOther
can just read660 -
Owner
andGroup
can read and write640 -
Owner
can read and write, andGroup
can read777 and 666 are rarely used, except in
/tmp
.Thanks Ilmari Karonen for pointing out the ones in common usage!