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?
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:It looks up all elements below
/usr/bin
and queries the RPM database for the corresponding package, deduplicates the RPM packages list and runsrpm --setperms
for each applicable RPM package.