In my Ubuntu version the man ls has the next info about --directory:
list directory entries instead of contents, and do not dereference symbolic linksSo 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?
5 Answers
$ man ls
...
-d, --directory list directories themselves, not their contentsThe 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 playgroundIf you want a list of directories in the current directory you can use
ls -d */ 0 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 /binIf 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/ Let me explain with examples:
ls: list contents of a directoryls -dorls --directory: list directories themselves, not their contents
Examples:
ls -d android-sdk-linux/
# result
android-sdk-linux/
ls android-sdk-linux/
# result
add-ons build-tools platforms platform-tools SDK Readme.txt temp toolsYour case of ls -d this says to list only show me the directory I am in not its content (i.e. . in Linux terms), so the result is: ..
But if you had said: ls, then you will see all that is present in the current directory ..
ls -d list directories them self instead of their content. Files are listed as normal. Look into man lsto se description of all options.
. is the directory it self, the same you use when running a command from current directory, ./runscript.sh
.. is parent directory, the parent to the current directore, as in cd .. to move at step up in directory hieracy