如何从查找“type d"中排除此/current/dot 文件夹 [英] How to exclude this / current / dot folder from find "type d"

查看:10
本文介绍了如何从查找“type d"中排除此/current/dot 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

find . -type d

可用于查找某个起点以下的所有目录.但它也会返回当前目录 (.),这可能是不受欢迎的.怎么排除?

can be used to find all directories below some start point. But it returns the current directory (.) too, which may be undesired. How can it be excluded?

推荐答案

POSIX 7 解决方案:

find . ! -path . -type d

对于这种特殊情况(.),打高尔夫球比 mindepth 解决方案(24 对 26 个字符)更好,尽管这可能因为 <代码>!.

For this particular case (.), golfs better than the mindepth solution (24 vs 26 chars), although this is probably slightly harder to type because of the !.

要排除其他目录,这会打得不太好,并且需要一个 DRYness 变量:

To exclude other directories, this will golf less well and requires a variable for DRYness:

D="long_name"
find "$D" ! -path "$D" -type d

我在 !-mindepth 之间的决策树:

My decision tree between ! and -mindepth:

  • 脚本?使用 ! 实现可移植性.
  • 在 GNU 上的交互式会话?
    • 排除.?扔硬币.
    • 排除long_name?使用 -mindepth.
    • script? Use ! for portability.
    • interactive session on GNU?
      • exclude .? Throw a coin.
      • exclude long_name? Use -mindepth.

      这篇关于如何从查找“type d"中排除此/current/dot 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆