Listing only directories via scripting is deceptively difficult. This recipe introduces multiple ways of listing only directories.
Listing only directories - alternative methods
Getting ready
g ready There are multiple ways of listing directories only. The dir command is similar to ls, but with fewer options. We can also list directories with ls and find.
How to do it...
Directories in the current path can be displayed in the following ways:
- Use ls with -d to print directories:
$ ls -d */
- Use ls -F with grep:
$ ls -F | grep "/$"
- Use ls -l with grep:
$ ls -l | grep "^d...