0

Using chmod, I accidentally changed everything in a bin folder and now sudo/su doesn't work.

I know rpm -q --whatprovides can provide which RPM provides a specific file. and rpm --setperms can restore everything provided by a RPM.

Is there a way to restore the permissions of all the files in a folder using rpm?

eng3
  • 167
  • 10

1 Answers1

2

I'm afraid the built-in features don't apply per directory. However the following might be a solution…let's assume you messed up /usr/bin permissions recursively, the following might help:

rpm --setperms $(rpm -qf $(find /usr/bin) | sort -u)

It looks up all elements below /usr/bin and queries the RPM database for the corresponding package, deduplicates the RPM packages list and runs rpm --setperms for each applicable RPM package.

rsc
  • 357
  • 1
  • 6