Shell script to list all files in a directory and subdirectories
- how to show all directories in linux
- how to list all directories in linux
- how to show hidden directories in linux
- how to view all directories in linux
Linux list files.
Linux list directories and subdirectories without filesHow to List Only Directories in Linux
The ls command in Linux is used for listing the contents of any directory.
By default, it lists all the contents, be it a file or a directory or a link or a named pipe.
But what if you want to list only the directories?
How do you do that?
Like anything in Linux, there are several ways to accomplish the same task. Listing only the directories is no different:
- ls -d */
- ls -l | grep '^d'
- find . -maxdepth 1 -type d
- echo */
- tree -d -L 1
Don't worry.
List all files in a directory linux
I'll explain things in detail. Here's the content of the directory I am going to use in the examples here:
Use ls command to list directories only
It is always good to do it with the familiar ls command because this is the command you use for displaying the content of a directory.
To list only the subdirectories, use the option with ls command like this:
Here's the output it shows:
Why ?
Because without it, will only return the directory name. The option list directories not its contents (which includes file, directories etc).
The is a pattern. With , you l
- how to show only directories in linux
- how to show hidden directories in linux terminal