Skip to content

Instantly share code, notes, and snippets.

@fabiante
Created November 3, 2018 18:13
Show Gist options
  • Save fabiante/a2375b482f8e25f5d03ff737252c27fe to your computer and use it in GitHub Desktop.
Save fabiante/a2375b482f8e25f5d03ff737252c27fe to your computer and use it in GitHub Desktop.
Change Linux Folder An File Permission Recursively
#!/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
@fabiante
Copy link
Author

fabiante commented Nov 3, 2018

Found on Stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment