Though listing only directories seems to be a simple task, many would not be able to do it. I have seen this often, even when asked to people who are good at shell scripting. This recipe is worth knowing since it introduces multiple ways of listing only directories with various tricky 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. But, it is wrong. The
dir command is just another command like
ls with fewer options than
ls. Let's see how to list directories.
There are four ways in which directories in the current path can be displayed. They are: