29

So I did a chmod -x chmod. How I can fix this problem? How do I give execute rights back to chmod?

Rook
  • 2,727

10 Answers10

46

In Linux:

/lib/ld-linux.so.2 /bin/chmod +x /bin/chmod

http://www.slideshare.net/cog/chmod-x-chmod

bindbn
  • 5,321
18

Use python:

# python
Python> import os
Python> os.chmod("/bin/chmod",0755)
18

This relies on the fact that permissions of a destination file are preserved rather than the source file when it is being copied over. We're "borrowing" the permissions of ls:

cp /bin/ls /tmp/chmod.tmp
cp /bin/chmod /tmp/chmod.tmp
mv /tmp/chmod.tmp /bin/chmod
10

Using Perl:

% perl -e 'chmod 0755, qw[/bin/chmod]'
Alnitak
  • 21,641
7

setfacl -m u::rx /bin/chmod

... will grant the owner execute permissions.

But, the /lib/ld-linux.so.2 trick is neat. :)

5

This is weird... I saw something like this a few days ago via someone's tweet...

http://www.slideshare.net/cog/chmod-x-chmod

ThatGraemeGuy
  • 15,788
5

Should you be on a system where /bin/chmod can't be loaded by the dynamic linker:

# /bin/mv /bin/chmod /bin/chmod.tmp
# install -p -m 755 /bin/chmod.tmp /bin/chmod

This works on my MacOS X system.

Alnitak
  • 21,641
2

/rescue/chmod 555 /bin/chmod

I think you could also use mtree.

Darius
  • 121
2

I suspect this is not a real question: http://www.slideshare.net/cog/chmod-x-chmod

  • Reinstall chown: sudo apt-get install --reinstall coreutils
  • perl -e 'chmod 0755, "chmod"'
  • more examples in the slides
Julien
  • 1,048
1

create a new chmod and use that for the original

umask 000
cat chmod > ~/my-chmod
~/my-chmod a+x chmod
Kevin M
  • 2,322