0

By mistake I have corrupted python file.

gauravv@ubuntu:~/Documents$ cp test.py /usr/local/bin/python cp: cannot create regular file ‘/usr/local/bin/python’: Permission denied gauravv@ubuntu:~/Documents$ sudo cp test.py /usr/local/bin/python [sudo] password for gauravv: gauravv@ubuntu:~/Documents$ 

Now I am getting this error

gauravv@ubuntu:/usr/local/bin$ python bash: /usr/local/bin/python: /usr/local/bin/python: bad interpreter: Too many levels of symbolic links gauravv@ubuntu:/usr/local/bin$ 

Any way to restore this file w/o installation.

3
  • 1
    You replaced python interpreter with your test.py and now you want to restore it? No its not possible. Commented Sep 10, 2014 at 6:41
  • Copy it from another machine. Commented Sep 10, 2014 at 6:50
  • isn't it a question (like all your others) for unix.stackexchange.com ? Commented Sep 10, 2014 at 8:17

1 Answer 1

1

Depending on your distribution /usr/local/bin/python was probably just a link to the actual binary, which you can definitely restore. All you need to do is find the original binary. Look in places like /usr/bin.

Then restore the link: sudo ln -s /usr/bin/python /usr/local/bin/python

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, that is correct because python was the symbolic link but my work has corrupted the actual file too. gauravv@ubuntu:/usr/local/bin$ cat python2 |more #!/usr/local/bin/python import sys print(sys.platform) print(2100) x='spam!' print(x*8) gauravv@ubuntu:/usr/local/bin$ cat python2.7 |more #!/usr/local/bin/python import sys print(sys.platform) print(2100) x='spam!' print(x*8) gauravv@ubuntu:/usr/local/bin$
If you have really overwritten the original binary, start your ubuntu version from a live cd and copy the python binary on a USB stick. Then boot into your installation and restore the file.
Thanks guys I got the python file from ubuntu default directory. After copy from there it is working now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.