While the -d
flag does prevent ls
from descending into directories, that is literally exactly what it does. It does not mean list only directories. There is a subtle difference between these two statements in that if you run ls -d some_file
, then ls
is going to show you some_file
. Since you are using shell globbing (./*
), this glob is expanding to include the files in the current directory, as well as the directories in the current directory. Since the shell is what performs globbing and expansion, and not ls
, the ls
is receiving a list of files.
To work around this, you need to ensure the shell glob does not include regular files. You can do this by using a trailing /
on the glob. Since /
is a special character forbidden in file names, but which denotes the separation between directories, you can use it to match only directories.
So for example:
ls -d */
-d
will preventls
from descending into directories - it won't prevented from listing files that are part of the shell's expansion of the./*
glob – steeldriver Jun 04 '18 at 18:18ls filename
, then ls will return the information aboutfilename
. You might tryfind . -maxdepth 1 -type d -ls
– doneal24 Jun 04 '18 at 18:21