• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2466
  • Last Modified:

ls and its parameters

I just need syntax for ls whereby I get a list of subdirectories also but without the files existing in it!!
1 Solution
As far as I know there's not any universal way to list only directories with "ls". It can be done easily, however, with "find". The command that you'd use would be "find path -type d -print". Most implementations of "find" allow you to leave off the "-print", that being the default. behaviour. By default "find" recursively descends into directory trees. On implementations that support it (GNU find for one), you can get a behaviour more like "ls" by using "find path -type f -maxdepth 1 -print". For more information, see the man pages for "find".

   # ls -Rd  

   I'm not sure how the output looks like.

  Why don't you try the du command

   # du .   <- this will give you a listing of directories within current dir along with the total size for each.  and a cummulative at the end of the listing.

   If you want just the dirname and not the figures, pipe the command to a "cut"  

   # du . | cut -d" " -f1

I hope this helps,

evansnfAuthor Commented:
Samri.... I used du.... it's what I reqd.... Thanx
try this
ls -Rl|egrep "^d"
this will look for a d in the first char, which all dirs have

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now