Bash 如何排除“.git”,然后备份和还原文件夹和文件的所有者和权限?

Bash 如何排除“.git”,然后备份和还原文件夹和文件的所有者和权限?,bash,acl,Bash,Acl,我更喜欢使用bash脚本,因为getfacl,setfacl有一个大问题(bug) 在我问这个问题之前,我还搜索了一种纯bash脚本的方法来备份和恢复所有者和权限。遗憾的是,没有人承认完美的答案 然后,我使用一种简单的方法备份和恢复所有者和权限: getfacl -R . >permissions.facl setfacl --restore=permissions.facl 如果我想从中排除.git,怎么办 是的,你可以 例如,我的目录看起来像 [root@967dd7743677 t

我更喜欢使用bash脚本,因为
getfacl,setfacl
有一个大问题(bug)

在我问这个问题之前,我还搜索了一种纯
bash
脚本的方法来备份和恢复
所有者和权限
。遗憾的是,没有人承认完美的答案

然后,我使用一种简单的方法备份和恢复所有者和权限:

getfacl -R . >permissions.facl
setfacl --restore=permissions.facl
如果我想从
中排除
.git
,怎么办

是的,你可以

例如,我的目录看起来像

[root@967dd7743677 test]# ls -la
total 20
drwxr-xr-x 4 root root 4096 Jan 11 06:37 .
drwxr-xr-x 1 root root 4096 Jan  2 11:08 ..
drwxr-xr-x 8 root root 4096 Jan  2 12:56 .git
drwxr-xr-x 2 root root 4096 Jan 11 06:37 1one
-rw-r--r-- 1 root root   19 Jan  2 12:55 testfile
[root@967dd7743677 test]#
通过使用
find
可以排除所需的任何目录

find . -type f -not -path '*/\.git/*' -exec getfacl -R {} \;
因此,我们通过
-exec
调用
getfacl-R

您可以重定向输出

find . -type f -not -path '*/\.git/*' -exec getfacl -R {} \; > permissions.facl

希望有帮助。

应该在
查找中添加
-depth
我想要所有文件夹和文件,只需排除
.git
。我想
-depth
的结果并不重要。