Re: Newbie - How to get the directory listing only

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 09/24/05


Date: Sat, 24 Sep 2005 11:56:00 -0400

In article <1127565113.531671.264100@g47g2000cwa.googlegroups.com>,
 "PradeepR" <pradeep.ravle@gmail.com> wrote:

> I am trying to find a way to list only the directories in particular
> UNIX folder. I have tried to find the command in the Net, but without
> success.
>
> I have tried
> ls -d
> ls -d *
>
> What it does is, displays files as well as directories. The only
> difference was that, it did not display the files under that directory.

The -d option means not to descend *into* directories (i.e. list the
directory itself, not its contents), it doesn't mean to list only
directories. Try:

ls -d */.

This will also include symbolic links that point to directories, though.

Another solution is:

find * -type d -print -prune

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages