List sub-directories with ls [closed]

2020-02-20 07:52发布

How could I list sub-directories with ls, with '-d' only the current directory is shown. I want something like find . -type d -maxdepth 1 would give me.

标签: linux shell
3条回答
Deceive 欺骗
2楼-- · 2020-02-20 07:54

This should help:

ls -d */

*/ will only match directories under the current dir. The output directory names will probably contain the trailing '/' though.

查看更多
老娘就宠你
3楼-- · 2020-02-20 08:09

ls -d */ and ls -d */*/ seem to work just fine.

查看更多
smile是对你的礼貌
4楼-- · 2020-02-20 08:15

You can combine with grep:

ls -l | grep '^d'

To get just the filenames:

ls -l | grep '^d' | awk '{ print $9 }'

You can make this into a handy alias:

alias ldir="ls -l | grep '^d'"
查看更多
登录 后发表回答