Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!hunt From: hunt@dg-rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.questions Subject: Re: Can ls be made to only list directories? Message-ID: <1990Sep2.041029.1380@dg-rtp.dg.com> Date: 2 Sep 90 04:10:29 GMT References: <90243.151817SML108@psuvm.psu.edu> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hunt@dg-rtp.dg.com Organization: Data General Corp., Research Triangle Park, NC Lines: 29 In article <90243.151817SML108@psuvm.psu.edu>, SML108@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@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.