I accidentally run the following command as root chown mike -Rf / backups the point is that I added a space between / and backups my mistake, I stopped the command after 1-2 seconds, how can I recover from this? I have problems with DirectAdmin right now for example when accessing it I recive the error:

Unable to determine Usertype
user.conf needs to be repaired

Or I stopped recieving emails, I dont even know what else is messed up right now...

  • 2
    Since it sounds like you have backups, I suggest comparing ownership info with the backups.
    – derobert
    May 1 '13 at 15:53
  • Note that the chown may also have cleared any setuid or setgid bits on the affected files, even if they were originally owned by root. May 1 '13 at 22:25

There is no way to change this back without reverting to your backup as the system does not keep track of revision of ownership.

Best is to make a backup now, so any further changes can be rolled back.

Reinstalling the packages on your system probably resolves most of the ownership problems. On Debian/Ubuntu I would do:

apt-get install --reinstall package

on an rpm based system something like rpm -Uvh --force package.rpm for anything that is giving trouble. If properly setup a package will not overwrite configuration files that you changed.

If you have another similar system, or a backup you can retrieve original ownership information from that an apply to your system. First make list of files and directories you are interested in using:

find / -user mike

and use that list to find not-mike-owned files in the backup or similar system.

  • I suggest you to check this answer about package reinstallation under a Debian based system.
    – Totor
    May 1 '13 at 23:09

That depends on the OS you are running.

If it is Solaris 10 and older, you can fix all the owner issues affecting files and directories belonging to a package with the following command:

pkgchk -f

With Solaris 11, that would be:

pkg fix

I believe AIX has a similar package fix command.

If you run a rpm based OS (Red Hat, Fedora and the likes), you should be able to run

rpm -aV

to detect the files and directories with discrepancies against the package database. You might then fix them by running:

rpm --setugids <package-name>

But you would need to pass each affected package name. Alternatively, you might simply run:

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

If you are running a debian based OS, I'm afraid file ownership isn't stored in the package database so you would need to either use your backup if any as a reference to restore the ownership, or find a similar system for the same.


I did exactly the same mistake, by a typographic error at the end of the sentence

chown -R root:root /folder/subfolder /

I didn't realize the space before the slash :(

Hopefully, asking here, finally I solved the problem, taking owner and group from another installed Debian server. In that server, I did:

find / -not -path '/proc/*' -not -path '/var/www/*' -not -path '/home/*' ! \(  -name root -o  -group root \) | xargs stat --format 'chown %U:%G %n' | sort -k 2,3 > chown_owner_and_group.sh
chmod +X chown_owner_and_group.sh

Then, I copy the file to the server where I need to restore the owner and group of files, and did an:

  • Wow, thank you for this answer. Totally saved my pc! Dec 29 '19 at 13:45
  • Sincerely, when I did it, I was afraid to reboot for first time that server ... but ALL WORKED!!! I had more to win than to loose ;) I am glad it helped you. Dec 30 '19 at 11:08

I'm afraid that the only solution you have is to compare with another installation of the same distribution and reset the owners correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.