Created
October 5, 2013 19:35
-
-
Save PerpetualBeta/6845202 to your computer and use it in GitHub Desktop.
Bash script to recursively chmod the permissions of files or folders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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