How to Find the List of Directories in a Directory in Linux/Mac OS X?

Anyone who has used command line on a terminal must have used the linux command “ls” to list the files and directories in a directory. Simple use of “ls” command will list directory and files in a given directory.

Often you might want to know only about the directories in a directory.

One can use the command “ls” with “-d” option to get directories within a directory. Here is how to get the list of directories

ls -d */

Remember that the above command will not function recursively. This will just list all the directories in the current directory. For example, if a current directory contains both files and directories, we can use

ls -lt

to get the list of files and directories like this

ls -lt to list files and directories
ls -lt to list files and directories

Here we have two files and three directories (highlighted in red). To list only the directories, if we use

ls -d */

we get the list of directories as below

ls -d */ list only the directories

Using “ls -d */” only lists the names of the directories. However, if you need more information about each of the directories, we can use


ls -ld */

And we will get the following results

ls -ld */ : list directories with more information