Ubuntu – What does `ls –directory` stand for

command linels

In my Ubuntu version the man ls has the next info about –directory:

list directory entries instead of contents, and do not dereference symbolic links

So I'm a little confused how it works.
I used the command ls --directory and I expected a list with all directories but instead I got .

So what exactly does ls --directory or ls -d do?

Best Answer

$ man ls
...
-d, --directory
              list directories themselves, not their contents

The current directory is represented as . so that's what ls -d is listing.

The directories inside the current directory are contents of the directory, and are therefore not shown with this option.

I use the -d option in an alias to display hidden files and directories

alias l.='ls -dC .* --color'

Without -d, this will list out the contents of the hidden directories too, which isn't what I want.

Another use for it is when I want to see metadata of a directory using the -l option, not its contents:

$ ls -ld playground
drwxr-xr-x 72 zanna zanna 12288 Mar  1 23:10 playground

If you want a list of directories in the current directory you can use

ls -d */
Related Question