1

I have python file my_script.py

When I run:

chmod +x my_script.py

I end up with two files that are called my_script.py, one executable file and one python file, when I try to get the size of the file:

du -sh my_script.py

I am getting the size of the python file (4.0K), but I want to know the size of the executable.

Is there a way to change a name of the executable file? To something say my_script without .py ?

2
  • They can't both be called the same - is one my_script.pyc by any chance? Mar 15, 2015 at 8:37
  • Thanks everyone who tried to help, I think my misunderstanding of what happens when chmod +x my_script.py is ran is pretty severe, your answers have pointed that out :).
    – Akavall
    Mar 15, 2015 at 13:46

2 Answers 2

2

There is only 1 file, my_script.py. Doing a simple chmod +x does NOT "end up with two files called my_script.py" (what would the 2nd my_script.py be called?).

Since Python is an interpreted language, you might want to consider the size of the python interpreter, and both the dynamic libraries and interpreted libraries it uses.

When the execve system call (see man 2 execve) notices that my_script.py is executable (has the x bit set), and begins with "#!<interpreter>" it runs <interpreter> my_script.py (interpreter> is probably /usr/bin/python in your case).

So, you can simply mv my_script.py my_script. Unlike that other operating system, Unix/Linux filenames do NOT govern how the files are executed.

2
  • chmod +x does not create a binary file, it just marks the file as executable (to be executed with python), so in order to run the executable I still need python installed on my system, is this right?
    – Akavall
    Mar 15, 2015 at 13:53
  • Yes, you need python, and both the dynamic libraries and interpreted (Python) libraries.
    – waltinator
    Mar 18, 2015 at 16:37
1

Execute this command to change name of file while making it executable.

chmod +x my_script.py && mv my_script.py mv_myscript

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .