Skip to content

Instantly share code, notes, and snippets.

@markhilton
Created October 21, 2018 19:44
Show Gist options
  • Save markhilton/f888c0b14306b38bfcd633e56a86713f to your computer and use it in GitHub Desktop.
Save markhilton/f888c0b14306b38bfcd633e56a86713f to your computer and use it in GitHub Desktop.
Set recursively default directories (755) & files (644) privileges. Usage: fix_privileges.sh $path
#!/bin/bash
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "ERROR: path argument is required, $# provided"
if [[ ! -d "$1" ]]; then
echo "ERROR: specified path is not a valid directory"
exit 1
fi
# To change all the directories to 755 (drwxr-xr-x):
find $1 -type d -exec chmod 755 {} \;
# To change all the files to 644 (-rw-r--r--):
find $1 -type f -exec chmod 644 {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment