May 2013
Beginner to intermediate
384 pages
7h 40m
English
Listing only directories via scripting can be deceptively difficult. This recipe is worth knowing since it introduces multiple ways of listing only directories with various useful techniques.
There are multiple ways of listing directories only. When you ask people about these techniques, the first answer that they would probably give is dir. However, the dir command is just another command like ls, but with fewer options. Let us see how to list directories.
There are several ways in which directories in the current path can be displayed:
ls with -l to print directories:
$ ls -d */
ls -F with grep:
$ ls -F | grep "/$"
ls -l with grep:
$ ls -l | grep "^d" ...Read now
Unlock full access