What does `ls --directory` stand for?
$ 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 */
Using ls
only with -d
is almost useless. It gives information about the directory itself. It does not list its contents.
That is why you do not see a list of directories. The directories that you expected to see are the "contents" of the current directory
If you run simply ls -d
it shows the current directory by .
.
If makes sense to run it with other keys like -l
.
ls -ld
will show permissions of the current directory.
pilot6@Pilot6:~$ ls -ld
drwxrwxr-x 1 pilot6 pilot6 2570 Mar 4 12:14 .
You can also see permissions of any other directory like
ls -ld /bin
pilot6@Pilot6:~$ ls -ld /bin
drwxr-xr-x 1 root root 2584 Feb 25 15:19 /bin
If you run ls -l
without -d
you will have the list of all permissions for files and folders in the current directory. If you do not need it, that's a good example for ls -ld
usage.
You can list directories in the current one by
ls -d */
Using ls -d
by itself is fairly useless because without a parameter it always returns .
. After you specify a parameter it makes sense though. For example if your user name is rick
and you want to see all the directories in your home use:
$ ls -d /home/rick/*/
/home/rick/AAC/ /home/rick/EnhanceIO/ /home/rick/silentcast/
/home/rick/assembly/ /home/rick/EnhanceIO-master/ /home/rick/Templates/
/home/rick/bin/ /home/rick/log/ /home/rick/test/
/home/rick/Desktop/ /home/rick/Music/ /home/rick/tmpe/
/home/rick/Documents/ /home/rick/Pictures/ /home/rick/Videos/
/home/rick/Downloads/ /home/rick/Public/