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?

2 Answers2

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 {} \;
matzeri
  • 961
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";'