aspose file tools*
The moose likes Linux / UNIX and the fly likes To list only the directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "To list only the directory" Watch "To list only the directory" New topic
Author

To list only the directory

Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Hi,

Anyone can help me in getting the command to list only directory. I tried the command ls -d. However, it will only list the "." only.

Cheers,
-Biswa


Thanks<br />-Swosti
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You mean, to make a list of all the subdirectories of the current directory? How about

find . -type d -maxdepth 1


[Jess in Action][AskingGoodQuestions]
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Thanks so much.

However, the maxdepth isn't working.showing the following error. It's working upto find . -type d

bash-2.03$ find . -type d -maxdepth 1
find: bad option -maxdepth
find: path-list predicate-list
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

-maxdepth is a feature of GNU find (Linux) and the BSD-ish find on Mac OS X; it may not be POSIX, so some older "find" implementations won't have it. What OS are you using?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
or maybe something like:



It does the equavalent of what a human might do:

generate a full-details file listing
select only those lines which start with d (for directory)
then only show the ninth (filename) field

Pretty much every linux or unix system has awk, and its a great little tool.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 258

How about

ls -d */


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
It's sun OS 5.8.

Cheers,
-Biswa
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Anand Hariharan:
How about

ls -d */


I like that one.
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Thanks you so much !

Can I know the source where we can get these tips ?

Cheers,
-Biswa
[ January 26, 2007: Message edited by: Biswamohan Routray ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To list only the directory