[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Simple sh or alias to list directories

On Tue, Oct 17, 2000 at 02:36:05PM +0000, Thomas Halahan wrote:
> Hello,
> I am trying to determine an easy alias or sh script that will list
> only the directories in a directory.  It should have similar
> functionality to the ls command.  E.g.
> [tom]$ lsd ~
> should list only the directories in my home folder, not the files.
Maybe find can be your friend too:), like with

   $ find  -type d -maxdepth 1 -printf '%f\n'

Make it a function so you can pass an argument:

   $ function lsd(){
   ( cd ${1:-.}
     ls -d `find -type d -maxdepth 1 -name \* -printf '%f\n'`

Leave out the "-name \*" part if you want the "ls -a" behaviour.
Leave out the "ls -d" part and the backticks if you prefer a long
unsorted list of names. Happy hacking.

groetjes, carel

Reply to: