There are already many answers for this similar question. But none of them satisfy my requirements. I want
List all directories under a directory without using glob (
*
) syntax, i.e. I want to directly uselsdir somedir
Output should containing basename of the directories like when you just use
ls
, like:$ lsdir path/to/some/dir dir1 dir2 dir3 dir4
but not this:
$ lsdir path/to/dir path/to/dir/dir1 path/to/dir/dir2 path/to/dir/dir3 path/to/dir/dir4
To satisfy requirement 1, it seems feasible to define a function, but anyway we are going to use
-d
option, to list the directories themselves of thels
command parameters.And when using
-d
option,ls
list directory names with its parent prepended, like above.ls
format (color, align, sort) should be preserved.To satisfy requirement 2, we can use
find
but in this way we lose all thels
output format, like coloring (based on customized dircolors theme), alignment (output in aligned columns), sorting (sorting customized with various flags and in a column-first manner), and maybe some other things.
I know it's too greedy to want this many features simultaneously, and indeed I can live without all of them.
It's possible to emulate ls
output format manually but that's too inconsistent.
I wonder if there is a way to achieve this and still utilize ls
, i.e. how to achieve requirement 2 using ls
.