Can ls be made to only list directories?

Greg Hunt hunt at dg-rtp.dg.com
Sun Sep 2 14:10:29 AEST 1990


In article <90243.151817SML108 at psuvm.psu.edu>, SML108 at psuvm.psu.edu
(Scott the Great) writes:
> As the subject asks, is there a set of options which will limit
> ls to listing directories?
> 
> Scott Le Grand aka sml10*@psuvm.psu.edu
> 

I don't think there is a set of switches to ls that will limit it to
only printing directories.  The quickest thing I could come up with 
was this:

    ls -ld * | awk '/^d/{print $0}'

This runs the output of ls through awk, printing only those lines that
are for directories.  You need the 'ls -l' to get the long listing
which puts a d at the beginning of the line for directories (which awk
then searches for).  You need the 'ls -d' to get ls to list only the
directory itself and not its contents.

If you want to get just the names output instead of the ls -l line,
change the $0 to $9.

Enjoy!

--
Greg Hunt                        Internet: hunt at dg-rtp.dg.com
DG/UX Kernel Development         UUCP:     {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC       These opinions are mine, not DG's.



More information about the Comp.unix.questions mailing list