不使用递归查找
是否可以以某种方式使用 find
命令,使其不会递归到子目录中?例如,
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
像 find DirsRoot --do-not-recurse -type f
这样的结果只会是 File1, File2
?
Is it possible to use the find
command in some way that it will not recurse into the sub-directories? For example,
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
And the result of something like find DirsRoot --do-not-recurse -type f
will be only File1, File2
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为根据您当前的命令结构,您将通过
-maxdepth 1
选项获得您想要的结果。如果没有,您可以尝试查看的 手册页找到
。相关条目(为了方便起见):
您的选择基本上是:
或者:
I think you'll get what you want with the
-maxdepth 1
option, based on your current command structure. If not, you can try looking at the man page forfind
.Relevant entry (for convenience's sake):
Your options basically are:
Or:
我相信您正在寻找
-maxdepth 1
。I believe you are looking for
-maxdepth 1
.如果您正在寻找 POSIX 兼容的解决方案:
cd DirsRoot &&寻找 。 -类型 f -print -o -name 。 -o -prune
-maxdepth 不是 POSIX 兼容选项。
If you look for POSIX compliant solution:
cd DirsRoot && find . -type f -print -o -name . -o -prune
-maxdepth is not POSIX compliant option.
是的,可以通过在 find 命令中使用 -maxdepth 选项
从手册
man find
Yes it is possible by using -maxdepth option in find command
From the manual
man find