Newbie - How to get the directory listing only - Unix
This is a discussion on Newbie - How to get the directory listing only - Unix ; 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 ...
-
Newbie - How to get the directory listing only
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.
I am using SCO flavour of UNIX.
Excuse me if it is a Newbie question. Thanks for your attention.
-
Re: Newbie - How to get the directory listing only
PradeepR 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.
ls -al | grep ^d
or
ls -l | grep ^d
to omitt dotdirs
you might want to alias the commands
--
reply to usenet only
-
Re: Newbie - How to get the directory listing only
In article <1127565113.531671.264100@g47g2000cwa.googlegroups. com>,
"PradeepR" 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 ***
-
Re: Newbie - How to get the directory listing only
Yes, it works. Thanks mate.
-
Re: Newbie - How to get the directory listing only
-
Re: Newbie - How to get the directory listing only
For many non-ancient UNIX flavors, something like:
$ ls -d */
will suffice.
If that generally works for your flavor, you might also want to discard
stderr and ignore
error(s) in general.
E.g.:
$ ls -d */
ls: */: No such file or directory
$ echo $?
1
$ mkdir d
$ ls -d */
d/
$ echo $?
0
$ rmdir d
$ 2>>/dev/null ls -d */ || :
$ echo $?
0
$