是否有可能以某种方式使用find
命令,它不会递归到子目录中?例如,找不到递归
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
和类似find DirsRoot --donotrecuourse -type f
结果将是只File1, File2
?
是否有可能以某种方式使用find
命令,它不会递归到子目录中?例如,找不到递归
DirsRoot
|-->SubDir1
| |-OtherFile1
|-->SubDir2
| |-OtherFile2
|-File1
|-File2
和类似find DirsRoot --donotrecuourse -type f
结果将是只File1, File2
?
我想你会得到你想要的-maxdepth 1
选项,根据你当前的命令结构。如果没有,您可以尝试查看man page的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.
您的选项基本上都是:
find DirsRoot/* -maxdepth 0 -type f #This does not show hidden files
或者:
find DirsRoot/ -maxdepth 1 -type f #This does show hidden files
我相信你正在寻找-maxdepth 1
。
对于OP的例子,我认为这需要'-maxdepth 1'? – 2010-10-13 15:41:35
是的,如果他完全按照他的例子使用命令,那么它会是1.我的错误。 – 2010-10-13 15:54:25
如果你看看POSIX兼容的解决方案:
cd DirsRoot && find . -type f -print -o -name . -o -prune
-maxdepth不符合POSIX选项。
对于OP的例子,我认为这需要'-maxdepth 1'? – 2010-10-13 15:42:48
@ Paul R:实际上,这种取决于他想如何处理隐藏的文件,但我已经修改了我的答案。对于他的例子'1'可能是他想要的。 – eldarerathis 2010-10-13 16:00:31
对我而言,'-maxdepth 0'没有显示*任何*文件,而是'-maxdepth 1'按预期工作,同时显示隐藏文件。 – 2016-03-02 20:11:40