如何排除此/当前/点文件夹查找“类型d” [英] How to exclude this / current / dot folder from find "type d"

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

问题描述

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


  • 脚本?使用可移植性。

  • GNU上的交互式会话?


    • exclude ?扔一枚硬币。

    • 排除 long_name ?使用 -mindepth

    • script? Use ! for portability.
    • interactive session on GNU?
      • exclude .? Throw a coin.
      • exclude long_name? Use -mindepth.

      这篇关于如何排除此/当前/点文件夹查找“类型d”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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