Listing *only* directories?
David Tilbrook
dt-hKuJ9UrQZDM at public.gmane.org
Tue Jan 13 06:08:36 UTC 2004
Peter Hiscocks wrote:
> Inspired by David Tilbrook's comments on linux, I ask you to consider the
> following:
>
> Amazingly, although 'ls' appears to have a zillion options, such as the
> somewhat obscure:
>
> -b, --escape
> print octal escapes for nongraphic characters
>
> there appears to be no way to do a directory list of *only* the
> subdirectories.
>
> My hopes were raised by ls -d:
>
> -d, --directory
> list directory entries instead of contents
>
> Alas, it's behaviour is illustrated by the following dialogue:
What about:
find . -type d | sed -e 's,^\./,,' -e '/\//d'
or
ls -l | awk '/^d/ {print $9}'
or
for X in * ; do
(cd $X >/dev/null 2>&1 && echo $X)
done
or ... but I seem to be slipping into the egregious use of
UNIX contest -- see http://www.qef.com/html/docs/egregious.pdf
(Henry was one of the other judges).
But this is something I do so often I have many tools such as:
l -d
rls -d # list all subdirectories
ls | fexists -d # fexists limits output to inputs
# that are directories
> -----------------------------------
> [phiscock-YIGruI5hBFo at public.gmane.org visual-vocab]$ ls -d
> .
> -----------------------------------
<snip>
>
> P.S. I'm also curious why ls -d would be useful. Presumably, there is more
> to it that meets the eye.
>
> P.
This is something I'm doing constantly.
F.Y.I., the l, rls, and fexists named above all date back to the 70s.
-- dt
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list