【问题标题】:`ls M*` displayes the subdirectory`ls M*` 显示子目录
【发布时间】:2018-09-11 12:44:29
【问题描述】:

我运行命令并接收结果为:

    $ ls M*
    ManagerGit
    $ ls m*
    ManagerGit

问题是 dir ManagerGit 不在当前目录中,
试试命令:

    $ ls | grep -i 'manage'
    Manager

是 dir Manage 的子目录

    tree -L 2
  ...
    ├── Manager
    │   └── ManagerGit
  ...

它背后的机制是什么?

【问题讨论】:

  • ls M* 替换为echo ls M* 看看会发生什么。

标签: bash ls subdirectory glob


【解决方案1】:

因为 shell 将 ls M* 扩展为 ls Manager - 即列出名为 Manager 的目录的内容。

ls 不知道如何过滤。我建议你这样做:

find . -depth 1 -name 'M*'

【讨论】:

    【解决方案2】:

    我总是发现ls -d M* 写起来更快更容易(而不是find ...),其中-d 执行以下操作:

    -d, --directory
        list directories themselves, not their contents
    

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 2013-03-14
      • 2011-07-07
      • 1970-01-01
      相关资源
      最近更新 更多