How to List Directories in Bash
Aashish Sunuwar
Feb 02, 2024
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
- How to Write to a File in Bash
- How to Overwrite File in Bash
- How to Open HTML File Using Bash
- How to Search for Files With a Filename Beginning With a Specified String in Bash
- How to Check if a File Is Empty in Bash
- How to Read File Into Variable in Bash