是否有可能以某種方式使用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