找不到递归

fil*_*ppo 236 unix shell find

是否有可能以find某种方式使用该命令,它不会递归到子目录中?例如,

DirsRoot
  |-->SubDir1
  |    |-OtherFile1
  |-->SubDir2
  |    |-OtherFile2
  |-File1
  |-File2
Run Code Online (Sandbox Code Playgroud)

而类似的结果find DirsRoot --donotrecuourse -type f只会是File1, File2

eld*_*his 357

-maxdepth 1根据您当前的命令结构,我认为您可以使用该选项获得所需内容.如果没有,你可以尝试寻找在手册页find.

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

-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.
Run Code Online (Sandbox Code Playgroud)

您的选择基本上是:

find DirsRoot/* -maxdepth 0 -type f #This does not show hidden files
Run Code Online (Sandbox Code Playgroud)

要么:

find DirsRoot/ -maxdepth 1 -type f #This does show hidden files
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,“-maxdepth 0”不显示*任何*文件,但“-maxdepth 1”正在按预期工作,并且也会显示隐藏文件。 (3认同)
  • @BruceWayne 请注意“find DirsRoot/* -maxdepth 0 -type f”中的“*”。如果您忽略它,它将不会显示任何文件。 (3认同)

waf*_*dox 32

我相信你在找-maxdepth 1.


sqr*_*163 17

如果您寻找符合POSIX标准的解决方案:

cd DirsRoot && find . -type f -print -o -name . -o -prune

-maxdepth不符合POSIX标准.


Jav*_*eel 5

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

find /DirsRoot/* -maxdepth 1 -type f
Run Code Online (Sandbox Code Playgroud)

来自手册

man find

-最大深度级别

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

-最大深度0

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