Linux Permissions – What Does the ‘Execute’ Permission Do?

linuxpermissions

I am shocked that I still don't understand "Execute" permission in Linux.

There are three permission – read, write, and execute. I understand that read and write literally, but what does execute do exactly?

Let's say I have example.php with execute permission. What can I do with example.php?

Best Answer

Basically it means you can tell the operating system to run the code in the file. For example, if the file was a binary executable, read access would allow you to view it, write access would allow you to modify it, but without execute permissions you would not be able to run the program. In the case of a script, its a little more complicted, because you don't necessarily need to 'run' the program, you can just read its contents into an interpreter, which itself has the execute privelige, but you do not need execute permissions on the script itself.

Some scripts in Linux are themselves executable, you will often see a line at the top like

#!/bin/bash

or

#!/bin/python

That line tells the kernel that the file can be executed by calling the relevant program (and isn't just text). Then you can just run your script like

./script

instead of having to do

python ./script