Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Quick and dirty script that's useful if files were copied from a drive
- # that was mounted with the incorrect permissions etc.
- # Given a dir as an arg, recursively set all file and dir permissions to
- # these defaults: -rw-r--r-- , drwxr-xr-x. Note that there is no recursion
- # limit imposed, so use with caution.
- DIR=755
- FILE=644
- USAGE="\nUsage: ./fix-permissions.sh <base-directory>"
- rec(){
- cd "$1"
- for x in *; do
- if [ -d "$x" ]; then
- chmod $DIR "$x"
- rec "$x"
- cd ..
- elif [ -f "$x" ]; then
- chmod $FILE "$x"
- fi
- done
- }
- if [ -d "$1" ]; then
- echo "Setting permissions of \"$1\" and its subdirectories to $DIR, and"
- echo "those of the files they contain to $FILE."
- chmod $DIR "$1"
- rec "$1"
- else
- >&2 echo -e "\"$1\" is not a directory or does not exist. $USAGE"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement