*BSD News Article 46685


Return to BSD News archive

Xref: sserve comp.unix.misc:17628 comp.unix.admin:30356 comp.unix.bsd:16674 comp.unix.programmer:26927 comp.unix.questions:66528 comp.unix.shell:23542
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!news.qut.edu.au!news
From: mdawson@eese.qut.edu.au (Murray Dawson)
Newsgroups: comp.unix.misc,comp.unix.admin,comp.unix.bsd,comp.unix.programmer,comp.unix.questions,comp.unix.shell
Subject: Re: A Unix command to obtain directory name only
Date: 12 Jul 1995 01:37:13 GMT
Organization: SPRC Speech Research Lab
Lines: 37
Distribution: world
Message-ID: <3tv909$2k0@stork.qut.edu.au>
References: <3tk3dc$4ml@rcp6.elan.af.mil>
Reply-To: mdawson@eese.qut.edu.au
NNTP-Posting-Host: markov.sprc.qut.edu.au
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit


In article <3tk3dc$4ml@rcp6.elan.af.mil>, Jay J Oh <OHJ%CSCADPS@mhs.elan.af.mil> writes:
>
>
>I am trying to invoke a unix command to obtain only directory names 
>listing for a given path.  I tried using 'ls -d *', but this includes 
>files also.  I also tried 'find -type d . -print'  but this command 
>recursively list all the subdirectories, which I don't want.
>
>Can anyone have any idea how to solve this problem?

How about:

   ls -p | grep /

(add -a to get .* directories)

and to get rid of the "/" in the output use:

   ls -p | grep / | awk -F/ '{print $1}'

and to make it a function under, say, bash:

   lsd () { ls -p $@ | grep / | awk -F/ '{print $1}' | more }

I might even add this to my .profile :)

Hope this helps,
Murray
-- 
|            - Murray I. Dawson -             |  
|        mdawson@markov.eese.qut.edu.au       |
|       Signal Processing Research Centre     |
|   QUT, GPO 2434, Brisbane 4001, Australia.  |
| phone: +61 7 864 2459 | fax: +61 7 864 1516 |