Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created Nov 21, 2021
Embed
What would you like to do?
# 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