How to List Directories in Bash

How to List Directories in Bash

Let’s have a look at listing the files and folders in Bash.

Use the ls Command to List Directories in Bash

We use the ls command to list items in the current directory in Bash.

ls

Output:

some_dir/
├── myFile1.txt
├── myFile2.txt
├── myFile3.txt
├── child_dir01/
├── child_dir02/
└── child_dir03/

However, we can use */ to print directories only since all directories finish in a / with the -d option to assure that only the directories’ names are displayed rather than their contents.

ls -d */

Output:

some_dir/
├── child_dir01/
├── child_dir02/
└── child_dir03/
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe

Related Article - Bash File

Related Article - Bash Directory