Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Quick and dirty script that's useful if files were copied from a drive
  4. # that was mounted with the incorrect permissions etc.
  5.  
  6. # Given a dir as an arg, recursively set all file and dir permissions to
  7. # these defaults: -rw-r--r-- , drwxr-xr-x. Note that there is no recursion
  8. # limit imposed, so use with caution.
  9.  
  10. DIR=755
  11. FILE=644
  12. USAGE="\nUsage: ./fix-permissions.sh <base-directory>"
  13.  
  14. rec(){
  15. cd "$1"
  16. for x in *; do
  17. if [ -d "$x" ]; then
  18. chmod $DIR "$x"
  19. rec "$x"
  20. cd ..
  21. elif [ -f "$x" ]; then
  22. chmod $FILE "$x"
  23. fi
  24. done
  25. }
  26.  
  27. if [ -d "$1" ]; then
  28. echo "Setting permissions of \"$1\" and its subdirectories to $DIR, and"
  29. echo "those of the files they contain to $FILE."
  30. chmod $DIR "$1"
  31. rec "$1"
  32. else
  33. >&2 echo -e "\"$1\" is not a directory or does not exist. $USAGE"
  34. exit 1
  35. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement