4

i wrote a py script to fetch page from web,it just read write permission enough,so my question is when we need execute permission?

mlzboy
  • 13,296
  • 23
  • 70
  • 94
  • possible duplicate of [review file permissions concept in the UNIX](http://stackoverflow.com/questions/12754748/review-file-permissions-concept-in-the-unix) – ivan_pozdeev Feb 22 '15 at 07:59

3 Answers3

6

Read/write is enough if you want to run it by typing python file.py. If you want to run it directly as if it were a compiled program, e.g. ./file.py, then you need execute permission (and the appropriate hash-bang line at the top).

Michael Ekstrand
  • 26,173
  • 8
  • 54
  • 88
5

It's required to do so if you need to run the script in this way: ./file.py. Keep in mind though, you need to put the path of python at the very top of the script: #!/usr/bin/python.

But wait, you need to make sure you have the proper path, to do that execute: which python.

Ruel
  • 14,301
  • 6
  • 34
  • 49
  • i'm under ubuntu lucid 10.04,use komodo edit,when i create a py file,it will give a shebang like,#!/usr/bin/env python is there sth different with #!/usr/bin/python what's common way? – mlzboy Sep 30 '10 at 02:32
  • 2
    See [this question](http://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script). `#!/usr/bin/env python` is more common. – snapshoe Sep 30 '10 at 02:52
0

If you want to be able to run it directly with $ file.py then you'll need the execute bit set. Otherwise you can run it with $ python file.py.

Daniel Roseman
  • 541,889
  • 55
  • 754
  • 786