Any reason to use "* /" in the command "ls -d * /" to specify directories?

I know there are other ways to do the same, for example

ls -l | grep "^d" 

or

 ls -F | grep "/$" 

I'm just curious about the reason for adding "* /" after "ls -d". Why just using "ls -d" doesn't work? Is there any story or trick?

+4
source share
2 answers

Adding the -d flag simply instructs ls simply list the directory entries, not their contents. * assigned by ls extends to all entries in the current directory, both files and dirs. Thus, ls -d * will list all entries in this directory without expanding the subdirectories. But if you use */ , then bash extends it to include only directories in this directory. But with just ls */ all directories will be expanded. Adding the -d flag prevents this, and you only get directories in this directory.

+6
source

If you use ls -d * , you will see not only directories, but also files. If you use ls -d */ , you will only see directories.

+2
source

All Articles