revert chmod 777 / -R

while executing a command i made a mistake and executed (ubuntu 10)

sudo chmod 777 / -R # okay you may laugh

now all my filesystem has 777 permitions , obviously i dont know which where the permitions for every folder and file in my 1TB drive :D

is there anyway i can revert this ?

Thanks in advance !!!


Solution 1:

Wow... that's pretty bad... The best thing you can do now is back up your personal data and reinstall your system.

Since that's probably not what you wanted to hear, the second best (and probably substantially more painful) thing to do is something like:

for package in `dpkg -l | awk '{print $2}'`; do
    apt-get install --reinstall $package
done

Note that this fix is purely theoretical (I've never tried it), but it will reinstall every package on your system (because as far as I can tell apt and dpkg don't have a "fix permissions" function like RPM). Reinstalling should fix the permissions on all the files that are in packages.

This "fix" may break other things, and you will probably still have some 777'd files floating around that aren't part of any packages, so you should follow up by finding all the stuff that's mode 777 and making sure the list looks sane.

Solution 2:

Try the following command

rpm --setperms $(rpm -qa)

This will reset all permissions to the defaults stored in the rpm database.

Or, if you want to go package by package and get some more output, try:

for p in $(rpm -qa) ; do echo "$p" ; rpm --setperms $p ; done

This will only revert files installed with rpm, not other files you created manually, or in your /home or installed in another way other than as an rpm package.

If you have a full backup, then you can get the permissions from there.