ls -d not doing what I'm told it should

Ubuntu 14.04 LTS Straight machine, no dual boot or anything.

I am in ~/scratch I want a list of directories only.

tree -dL 1

Got it!

man ls says:

-d List directories only instead of their contents.

info ls says:

-d List just the names of directories...

Clearly, this is not doing what I'm told it should. What don't I understand?


ls -d will list directory entries without their contents, it is not used to show only the directory entries inside a directory.

An example will make you clear:

$ tree
.
├── egg
├── spam
└── test
    ├── new
    └── old


$ ls *
egg  spam

test:
new  old


$ ls -d *
egg  spam  test

As you can see -d just makes sure that the contents of directory test is not being shown.

As already shown in this answer, to show only the directory entries, you can use */. The / after * ensures that only directories will be shown:

$ ls -d */
test/

This is analogous to:

$ for i in *; do [[ -d $i ]] && echo "$i"; done
test

Try this instead: ls -d */ it will list the directories in the current directory