Skip to content

Instantly share code, notes, and snippets.

@filipeandre
Created May 13, 2018 23:44
Show Gist options
  • Save filipeandre/07a3290ebd32b5084c93543e3398854a to your computer and use it in GitHub Desktop.
Save filipeandre/07a3290ebd32b5084c93543e3398854a to your computer and use it in GitHub Desktop.
Restore home directory permissions
#!/bin/bash
usage(){
echo "Usage: $0 username"
exit 1
}
restore(){
getent passwd $1
if [ $? -eq 0 ]; then
find /home/$1 -type d -print0 | xargs -0 chmod 0775
find /home/$1 -type f -print0 | xargs -0 chmod 0664
echo "Done."
else
echo "User does not exist!"
fi
}
[[ $# -ne 1 ]] && usage
restore $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment