Skip to content

Instantly share code, notes, and snippets.

@daks
Last active March 15, 2018 15:19
Show Gist options
  • Save daks/9322644 to your computer and use it in GitHub Desktop.
Save daks/9322644 to your computer and use it in GitHub Desktop.
restore permissions and user/group on Linux/Unix
# sometimes, when changing permission or ownership you run a command like
# chown -R www-data: .*
# and it does what you want correctly: change ownership on dotfiles
# but it does also what you don't want: change ownership on all files which are in the parent directory
# which is really bad
# the solution, taken from http://sysadminnotebook.blogspot.fr/2012/06/how-to-reset-folder-permissions-to.html
# 1. on a snapshot or another Debian installation run
find / -exec stat --format "chmod %a %n" {} \; > /tmp/restoreperms.sh
find / -exec stat --format 'chown %U:%G %n' {} \; >> /tmp/restoreperms.sh
# 2. on your screwed installation run
sh /tmp/restoreperms.sh
# other solutions consist on using information about packages (for Debian) but I haven't tested it
# and the solution to change permissions/ownership on dotfiles is to run (see http://blog.matoski.com/articles/debian-restore-var-ownership-permissions/)
chown -R /var/www/.[^.]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment