开发者

List sub-directories with ls [closed]

Closed. This questi开发者_如何学Goon is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

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.


This should help:

ls -d */

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


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'"


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜