【问题标题】:How to list only the dot files and dot folder names (without the content in them)如何仅列出点文件和点文件夹名称(不包含其中的内容)
【发布时间】:2014-04-19 22:45:28
【问题描述】:

我只想列出隐藏的文件和文件夹(以点开头)。当我使用命令时

ls .??*

我得到了输出

.gitignore

.git:
COMMIT_EDITMSG FETCH_HEAD     HEAD           ORIG_HEAD      branches       config         description    hooks          index          info           logs           objects        packed-refs    refs

我不想要文件夹中的内容。相反,我正在寻找仅列出文件夹的输出

.gitignore
.git [different color for the folders, like the normal ls]

【问题讨论】:

  • 你能解释一下为什么给出-1..我确实搜索了列出点文件并找到了ls..但没有找到没有目录的方法..当然对于使用它的人来说在它很容易找到之前..

标签: linux shell ls


【解决方案1】:

尝试:

ls -d .*

仅供参考

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

如果你的 ls 不是其他命令的别名,上面ls -d .* 的输出将在同一行输出文件/目录。如果您想将它们分别放在自己的行中:

ls -d1 .*

如果你想要彩色输出:

ls -d1 --color=auto .*

【讨论】:

    【解决方案2】:
    ls -d .??*
    

    -d 开关使 ls 将目录参数视为文件参数,并且不会列出其内容,而是显示通常的输出(手册页摘录,感谢@fedorqui):

    列出目录条目而不是内容,并且不要取消引用符号链接

    它与-l 和其他人很好地结合在一起,并且无需任何进一步的切换,默认为ls 的通常的多列视图。

    【讨论】:

    • 来自man ls, list directory entries instead of contents, and do not dereference symbolic links
    猜你喜欢
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2015-11-04
    • 2018-01-25
    相关资源
    最近更新 更多