Created
February 14, 2022 19:24
-
-
Save pmarreck/8c02f7f0d5f85bc282146ad55a518fea to your computer and use it in GitHub Desktop.
Back up file or directory permissions and owner metadata on a linux filesystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Creates a script file that restores your current filesystem permissions and owners in the event there's a mishap." | |
echo "Note: May need to be modified to handle double-quotes in filenames, excluding directories like proc or mnt, etc." | |
echo "Also, since 'find' does breadth-first traversal, it might make more sense to run the chmod and chown with -R," | |
echo "although that will make it take MUCH longer as it will be re-applying more specific permissions" | |
echo "on the way down." | |
sudo find / -name '*' -printf 'chmod %#m "%p"\nchown -h %u:%g "%p"\n' > fix-permissions.sh | |
echo "Complete. Now do 'chmod +x fix-permissions.sh; chown <yourusername> fix-permissions.sh' and run when you need to." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment