Bash:使用 -depth 和 -prune 进行查找以提供 cpio
我正在构建一个备份脚本,其中某些目录不应包含在备份存档中。
cd /;
find . -maxdepth 2 \
\( -path './sys' -o -path './dev' -o -path './proc' -o -path './media' -o -path './mnt' \) -prune \
-o -print
这只会找到我想要的文件和目录。
问题是 cpio
应提供以下选项,以避免恢复文件时出现权限问题。
find ... -depth ....
如果我添加 -深度
选项,返回的文件和目录将包含我想要避免的文件和目录。
我真的不明白查找手册中的这些句子:
-prune True; if the file is a directory, do not descend into it. If
-depth is given, false; no effect. Because -delete implies
-depth, you cannot usefully use -prune and -delete together.
I'm building a backup script where some directories should not be included in the backup archive.
cd /;
find . -maxdepth 2 \
\( -path './sys' -o -path './dev' -o -path './proc' -o -path './media' -o -path './mnt' \) -prune \
-o -print
This finds only the files and directories I want.
Problem is that cpio
should be fed with the following option in order to avoid problems with permissions when restoring files.
find ... -depth ....
And if I add the -depth
option, returned files and directories include those I want to avoid.
I really don't understand these sentences from the find manual:
-prune True; if the file is a directory, do not descend into it. If
-depth is given, false; no effect. Because -delete implies
-depth, you cannot usefully use -prune and -delete together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我引用本教程中的一段话,它可能会帮助您更好地理解
find
的-prune
选项。来源
I am quoting a passage from this tutorial which might offer better understanding of
-prune
option offind
.Source