Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created February 14, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/8c02f7f0d5f85bc282146ad55a518fea to your computer and use it in GitHub Desktop.
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
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