Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To list only the directory

 
Swosti Dipan Pal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean, to make a list of all the subdirectories of the current directory? How about

find . -type d -maxdepth 1
 
Swosti Dipan Pal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about

ls -d */
 
Swosti Dipan Pal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's sun OS 5.8.

Cheers,
-Biswa
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anand Hariharan:
How about

ls -d */


I like that one.
 
Swosti Dipan Pal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic