Created
November 3, 2018 18:13
-
-
Save fabiante/a2375b482f8e25f5d03ff737252c27fe to your computer and use it in GitHub Desktop.
Change Linux Folder An File Permission Recursively
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 | |
# syntax: setperm.s destdir | |
# | |
if [ -z $1 ] ; then echo "Requires single argument: <directoryname>" ; exit 1 ; fi | |
destdir=$1 | |
dirmode=0700 | |
filemode=0600 | |
YN=no | |
printf "\nThis will RECURSIVELY change the permissions for this entire branch:\n " | |
printf "\t$destdir\n" | |
printf "\tDirectories chmod = $dirmode\tFiles chmod = $filemode\n" | |
printf "Are you sure want to do this [$YN]? " | |
read YN | |
case $YN in | |
[yY]|[yY][eE][sS]) | |
# change permissions on files and directories. | |
find $destdir -type f -print0 | xargs -0 chmod $filemode $i | |
find $destdir -type d -print0 | xargs -0 chmod $dirmode $ii ;; | |
*) echo "\nBetter safe than sorry I always say.\n" ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found on Stackoverflow