bash - 如何排除`.git`然后备份和恢复文件夹和文件的所有者和权限?
问题描述
我更喜欢使用 bash 脚本,因为getfacl,setfacl
有很大的问题(bug)。
在我问这个问题之前,我也搜索了一种纯bash
脚本备份和恢复owner and permission
的方法。可惜没有人承认完美的答案。
然后我使用一种简单的方法来备份和恢复所有者和权限:
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
希望能帮助到你。
推荐阅读
- linux - 如何通过 ssh 代理?
- html - 如何将 a 的宽度设为自动?
- rxjs - 如何在 rxjs 中实现服务器轮询
- java - 为什么我的超类对象实例会影响我继承的类对象实例?
- python - 为什么我的进度条可以使用“打印”命令而不是 tkinter?
- amazon-web-services - https - 如何让用户通过 ELB 与 Jenkins 建立安全连接?
- reactjs - 使用 Typescript 的 create-react-app :当前未启用对实验性语法“classProperties”的支持
- flutter - 颤振应用程序使用摘要身份验证连接到 ip 相机
- javascript - 如何解决这个javascript数组删除方法问题
- android - 在底部导航颤振后面扩展容器