List Directories in Bash
Aashish Sunuwar
Jan 03, 2022

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/
Related Article - Bash File
- Write to a File in Bash
- Bash Overwrite File
- Open HTML File Using Bash
- Search for Files With a Filename Beginning With a Specified String in Bash
- Check if a File Is Empty in Bash
- Read File Into Variable in Bash
Related Article - Bash Directory
- Run Mkdir Only When the Directory Does Not Exist
- Change Directory in Bash
- Find the Current Folder Name in Bash
- Bash Create Directory
- Find Files and Folders in Linux