How to execute a file with (---x--x--x) Permissions and I am not the owner?

Felipe Alfaro Solana felipe.alfaro at gmail.com
Sun Aug 6 04:15:48 UTC 2006


> It's a python file and I tried running these two commands and get the
> following errors:

The problem is that only pure binary files can get executed with a
permission mask of 111 (--x--x--x). Python is a dynamic, interpreted
language, and thus, needs to be interpreted through the python
interpreter.

Let's take this sample Python program:

$ cat sample.py
#!/usr/bin/python
print "Hello"

If you "chmod 111" this program and try running it, the kernel will
see in the first line this is not a pure binary file and must be ran
using an interpreter or shell. In fact, the first line of the program
tells the kernel which shell or interpreter to use in order to run
this script. So, running

$ sample.py

is the same as running

$ /usr/bin/python sample.py

If the file sample.py has no read permissions on it, the python
interpreter won't be able to open it up for reading, then interpreting
and executing it. Thus, for shell scripts or interpreted programs, the
permission mask needs to explicitly grant the read permission (for
example, 555).




More information about the ubuntu-users mailing list