25

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.

Bernhard
  • 7,557
  • 2
  • 37
  • 39

3 Answers3

34

This should help:

ls -d */

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

Costi Ciudatu
  • 33,403
  • 5
  • 52
  • 89
6

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

Šimon Tóth
  • 33,420
  • 18
  • 94
  • 135
5

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'"
dogbane
  • 242,394
  • 72
  • 372
  • 395