setfacl -R 在 Cygwin 上不起作用

setfacl -R 在 Cygwin 上不起作用

我想更改基本目录中所有目录和文件的 ACL 和默认 ACL。在其他答案中(例如这个),-R使用该标志。但是,我得到

$ 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/

如何在 Cygwin 上递归设置 ACL 权限?

答案1

要对目录中包含的任何文件和目录重复该命令,您可以使用find及其-exec选项

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

答案2

这已经被测试过。

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}"

或者,作为更具可读性的东西,它可能是一个脚本,但更可能只是一个更好脚本的开始。 (这尚未经过测试。)

#!/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";'

相关内容