Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to recursively chmod the permissions of files or folders.
#!/bin/sh
# Traverse a directory starting at $path and change the permissions of all files
# or folders (determined with options) to $permissions
helpText=$"Usage: ${0##*/} -(f|d) permissions path";
permissions=$2;
path=$3;
if [[ $path ]]
then
if [[ ! -d $path ]]
then
echo "Path not found: $path";
exit 1;
fi
fi
while getopts "fd:" mode; do
case $mode in
f)
find "$path" -type f -exec chmod "$permissions" {} +
exit 0;
;;
d)
find "$path" -type d -exec chmod "$permissions" {} +
exit 0;
;;
*)
echo $helpText;
exit 1;
esac
done
echo $helpText;
exit 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.