cmd to view only directories

Hi All,

Plz tell me the cmd of viewing only directories. Suppose i am at bin directory and it contains another directory mails with lotz of files in it.

Now when ever I do ls -lt mails under bin directory it shows me all the files inside mails dir . But I just want to see only mails dir as an output not all of its contents(i.e files inside mails dir). Is there any switch for displaying directories only.

Plz let me know. I would be thankful. I am working on Solaris 5.8 platform.

Thnx..
Aru

If I understand your questions try:

ls .

This gives the files that live in the current directory, including the names of directories but not the files in those directories.

ls -d */

Only list the directories in the current directory

cheers

swapneel

ls -d */

Only list the directories in the current directory

cheers

swapneel

Dear friend thanks for reply. I have tried uising ls -d */ but its giving me following error

$ ls -d */
*/: No such file or directory

But there are few directories in bin folder. Please suggest some other solution.

Aru.

hi

try ls */

or

visit this page http://www.computerhope.com/unix/uls.htm
and have a look at directoy of file

Cheers

Swapneel

try
ls -l|grep ^d

have u tried dir command
type:- I cant understand what u looking for??? but i guess thats it...or u want to see files within dir also???

dir

do u want this??

ls -ld mails

Append this in profile:
alias lsd='ls -1F $* | grep '/$' '

type
lsd

This will display all the directories.
E.g.:-
dir_a/
dir_b/
mails/

Dude! That's a nice little alias.

I'm an alias junkie.. I'll make sure I add that one :wink:

Cheers

The given alias is quite ok for listings of the $PWD.
But if I remember correctly aliases (or better alii) are parameter ignorant.
If you wish to pass parameters you need to define a shell function.
For instance you could put this in your .shrc file.

lsd() { ls -p $*|grep /\$; }

Then you could say e.g.
lsd /etc /var

Of course the classic way to list directories is simply to use find
e.g. for a recursive search

find /var -type d

But you could restrict the descent to inodes of the same filesystem

find /var -xdev -type d

Or even limit the depth of descent

find /var -maxdepth 1 -type d

But better consult your Unix's manpage of find because despite
a common denominator the different finds all deviate slightly in their scope and syntax.
Probably the widest functionality is offered by GNU find,
as is part of findutils of Linux distros.

Note also, if you run find with restricted permissions as far as read and execute
of dirs is concerned that it's probably advisable to redirect stderr to /dev/null
to prevent error messages cluttering your find results.

I've never had a problem passing arg's to aliases. Consider the RH default, which aliases 'ls' to 'ls --color'..

Perhaps the problem is a "shell specific", one. In which case, we could chalk it up to another example of of how much bash RULES. :smiley:

Perhaps I was uttering imprecisely
(but as I am not a native English speaker this may excuse me)
The kind of alias you were mentioning like the notorious RedHat ls alias
(which I detest because it regularily spoils my aixterm, from where I log in to an RH box)
I would not really consider parameter processing like that of shell functions.
I think what the shell does here is simply a word splitting of tokens first,
and then the alias expansion before finally evaluating the whole expression.