0

I want to change the ACL and the default ACL for all directories and files in a base directory. In other answers (such as this one), the -R flag is used. However, I get

$ setfacl -R -m u::rwx my_dir/
setfacl: unknown option -- R
Try `setfacl --help' for more information.

# this is different from what's done on, e.g. Ubuntu
# setfacl -R -d -m u::rwx mydir/
$ setfacl -R -m d:u::rwx mydir/

How can I recursively set the ACL permissions on Cygwin?

  • setfacl in cygwin is not coming from Linux as base. What is the problem to use find my_dir -exec setfacl -m u::rwx {} \; ? – matzeri Sep 19 '18 at 9:38
  • That sounds great. Do you want to put it as an answer? – bballdave025 Sep 19 '18 at 15:32
1

To repeat the command for any file and directory contained in a directory you can use find and its -exec option

find my_dir -exec setfacl -m u::rwx {} \;
0

This has been tested.

outfile="permissions.out"; echo | tee -a "${outfile}"; echo "For directory:" | tee -a "${outfile}"; echo "$(pwd)" | tee -a "${outfile}"; find . -print0 | xargs -I'{}' -0 bash -c 'echo; echo " Changes for {}"; echo "Trying to change the group"; chgrp '"'"'my_group'"'"' "{}"; if [ -f "{}" -o -d "{}" ]; then echo; echo "User to rwx"; setfacl -m u::rwx "{}"; setfacl -m u:bballdave025:rwx "{}"; echo "User-default to rwx"; if [ -d "{}" ]; then setfacl -m d:u::rwx "{}"; setfacl -m d:u:bballdave025:rwx "{}"; else echo "  Not a directory, no defaults."; fi; echo "Group to rwx"; setfacl -m g::rwx "{}"; echo "Group-default to rwx"; if [ -d "{}" ]; then setfacl -m d:g::rwx "{}"; setfacl -m d:g:my_group:rwx "{}"; else echo "  Not a directory, no defaults."; fi; echo "Other to r-x"; setfacl -m o:r-x "{}"; echo "Other-default to r-x"; if [ -d "{}" ]; then setfacl -m d:o::r-x "{}"; else echo "  Not a directory, no defaults"; fi; else echo "  Not a file nor a directory, probably a permissions error."; fi; echo "Changing executable bit"; chmod a+x "{}"; echo -e "\nDone with {}\n\n\n";' | tee -a "${outfile}"

Or, as something somewhat more readable, which could be a script, but which is more likely just the start of a better script. (This hasn't been tested.)

#!/bin/bash

find $1 -print0 | \
xargs -I'{}' -0 bash -c \
'echo; '\
'echo " Changes for {}"; '\
'echo "Trying to change the group"; '\
'chgrp '"'"'my_group'"'"' "{}"; '\
'if [ -f "{}" -o -d "{}" ]; then '\
'  echo; '\
'  echo "User to rwx"; '\
'  setfacl -m u::rwx "{}"; '\
'  setfacl -m u:bballdave025:rwx "{}"; '\
'  echo "User-default to rwx"; '\
'  if [ -d "{}" ]; then '\
'    setfacl -m d:u::rwx "{}"; '\
'    setfacl -m d:u:bballdave025:rwx "{}"; '\
'  else '\
'    echo "  Not a directory, no defaults."; '\
'  fi; '\
'  echo "Group to rwx"; '\
'  setfacl -m g::rwx "{}"; '\
'  echo "Group-default to rwx"; '\
'  if [ -d "{}" ]; then '\
'    setfacl -m d:g::rwx "{}"; '\
'    setfacl -m d:g:my_group:rwx "{}"; '\
'  else '\
'    echo "  Not a directory, no defaults."; '\
'  fi; '\
'  echo "Other to r-x"; '\
'  setfacl -m o:r-x "{}"; '\
'  echo "Other-default to r-x"; '\
'  if [ -d "{}" ]; then '\
'    setfacl -m d:o::r-x "{}"; '\
'  else '
'    echo "  Not a directory, no defaults"; '\
'  fi; '\
'else '\
'  echo "  Not a file nor a directory, probably a permissions error."; '\
'fi; '\
'echo "Changing executable bit"; '\
'chmod a+x "{}"; '\
'echo -e "\nDone with {}\n\n\n";'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.