Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created November 21, 2021 11:12
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 ormaaj/0e51bb9c55ac1d6cbf25e8ad3a94fe7c to your computer and use it in GitHub Desktop.
Save ormaaj/0e51bb9c55ac1d6cbf25e8ad3a94fe7c to your computer and use it in GitHub Desktop.
# Quickly adds world read permissions to files and world read/write permissions
# to directories recursively. «-u user[:group]» will additionally chmod files
# and directories recursively.
function fixperms {
typeset -a paths
typeset chownUserGroup
until ${1+'false'}; do
case $1 in
-u)
if [[ -n $2 ]]; then
chownUserGroup=$2
command shift 2
else
echo 'Must supply a user:group for the -u option' >&2
return 1
fi
;;
--)
[[ -n $2 ]] && paths+=("${@:2}")
command shift "$#"
break
;;
*) [[ -d $1 ]] && paths+=("$1")
command shift
esac
done
(( ${#paths[@]} )) || paths+=(.)
find -- "${paths[@]}" \
\( \( -type d -exec chmod o+rx -- {} + \) -o \( -type f -exec chmod o+r -- {} + \) \) \
${chownUserGroup:+'-false'} -exec chown "$chownUserGroup" -- {} +
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment