考虑:
-maxdepth n
True if the depth of the current file into the tree is less than
or equal to n.
-mindepth n
True if the depth of the current file into the tree is greater
than or equal to n.
你好,
我想进一步解释Jon提出的使用-prune的建议。这并不是最容易使用的find选项之一,例如,如果要在当前目录中搜索,find命令看起来像:
find . \( -type d ! -name . -prune \) -o \( <the bit you want to look for> \)
这将阻止查找进入此目录中的子目录。
基本上,它的意思是,“修剪任何名称不是“。”(即当前目录)的目录。”
find命令从左到右对当前目录中找到的每个项目进行评估,因此在完成第一个元素(即修剪部分)后,它将继续使用第二个-o(OR'd)表达式中匹配的项目。
希望对你有所帮助。
祝好, Rob
您最好使用通配符。例如,如果您想在当前目录中查找所有的ksh脚本:
$ ls *.ksh
你甚至可以这样做
echo /specific/dir/*.jpg
因为通配符的展开是由您的 shell 完成的。输入
ls *.jpg
相当于输入
ls foo.jpg bar.jpg
假设foo.jpg和bar.jpg是当前目录中以“.jpg”结尾的所有文件。
使用-prune选项。