How to revert chown command?

In short: no.

You'll need to restore from a backup. (Some backup tools might have options to only restore only permission, others can list backed-up files with their permissions and you can use that to fix your system.)

If you don't have a backup, you'll need to fix all that manually.


Only if you know the user and group ownership of every file and directory under your / directory.

Even then, you've already clobbered the ownership of critical system files that need to be owned by root, including the sudo command. You'd probably need to mount the hard drive on another system -- and be aware that the other system likely won't have the same UID and GID mappings as the one you just clobbered.

Make a copy of the entire hard drive if you can, then reinstall your operating system. Once you've done that, you can try copying files back to the newly wiped system and restoring their ownerships. You can probably assume (though not 100% reliably) that everything under /home/foo is owned by user foo, and that each mail spool file under /var/mail is owned by the appropriate user (if you have e-mail on the system). You can likely get away without restoring most files that aren't under /home, depending on what you've done with the system.

And then start cultivating a habit of double-checking any command you run under sudo before you hit Enter.


If your distro is RPM based, you can restore ONLY files that installed by rpm packages.

To restore all package permissions:

rpm --setperms -a

To restore all package owner (user/group):

rpm --setugids -a

If -a doesn't run, you can execute a bash loop:

For permissions:

for x in $(rpm -qa); do rpm --setperms $x; done

For owner:

for x in $(rpm -qa); do rpm --setugids $x; done

Extracted from: http://www.sysadmit.com/2016/10/linux-restaurar-permisos-de-un-paquete.html