ls command to list only directories


By default when you run the ls command, it will show you all the files and directories in the directory you run this command.

If you want to only display the list of all the directories, you can make use of the -d option.

-d: Directories are listed as plain files (not searched recursively).

Note it will not work just by using the -d option, you would also need to add */

% ls -d */
/Applications	/System		/Volumes	/cores
/etc		/opt		/sbin		/usr
/Library	/Users		/bin		/dev		
/home		/private	/tmp		/var

The * is the wildcard to match any string and / to indicate that only directories should be listed.

If you also want to see hidden files you may add -a flag and -l to display it as a list.

% ls -lad */
ls command to list only directories
-




Have Questions? Post them here!