不使用递归查找

发布于 2024-09-27 06:59:16 字数 280 浏览 2 评论 0原文

是否可以以某种方式使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

极度宠爱 2024-10-04 06:59:16

我认为根据您当前的命令结构,您将通过 -maxdepth 1 选项获得您想要的结果。如果没有,您可以尝试查看 手册页找到

相关条目(为了方便起见):

-maxdepth levels
          Descend at most levels (a non-negative integer) levels of direc-
          tories below the command line arguments.   `-maxdepth  0'  means
          only  apply the tests and actions to the command line arguments.

您的选择基本上是:

# Do NOT show hidden files (beginning with ".", i.e., .*):
find DirsRoot/* -maxdepth 0 -type f

或者:

#  DO show hidden files:
find DirsRoot/ -maxdepth 1 -type f

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 for find.

Relevant entry (for convenience's sake):

-maxdepth levels
          Descend at most levels (a non-negative integer) levels of direc-
          tories below the command line arguments.   `-maxdepth  0'  means
          only  apply the tests and actions to the command line arguments.

Your options basically are:

# Do NOT show hidden files (beginning with ".", i.e., .*):
find DirsRoot/* -maxdepth 0 -type f

Or:

#  DO show hidden files:
find DirsRoot/ -maxdepth 1 -type f
变身佩奇 2024-10-04 06:59:16

我相信您正在寻找 -maxdepth 1

I believe you are looking for -maxdepth 1.

久光 2024-10-04 06:59:16

如果您正在寻找 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.

苄①跕圉湢 2024-10-04 06:59:16

是的,可以通过在 find 命令中使用 -maxdepth 选项

find /DirsRoot/* -maxdepth 1 -type f

从手册

man find

-最大深度级别

下降到起始点以下的最多级别(非负整数)目录级别。

-最大深度0

意味着仅将测试和操作应用于起点本身。

Yes it is possible by using -maxdepth option in find command

find /DirsRoot/* -maxdepth 1 -type f

From the manual

man find

-maxdepth levels

Descend at most levels (a non-negative integer) levels of directories below the starting-points.

-maxdepth 0

means only apply the tests and actions to the starting-points themselves.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文