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

Re: Simple sh or alias to list directories



  note that it won't list links to directories, you might want to use
-follow see below:

panther:~/rrr>l
total 6
drwxr-xr-x   2 esteffl  pbidev       512 Oct 17 09:15 dir
lrwxrwxrwx   1 esteffl  pbidev         3 Oct 17 09:15 dir.link -> dir
-rw-r--r--   1 esteffl  pbidev        14 Oct 17 09:15 file.txt
panther:~/rrr>find . -type d -print
.
./dir
panther:~/rrr>find . -follow -type d -print
.
./dir
./dir.link
panther:~/rrr>

  (I don't use -maxdepth in examples because it does not work on solaris
that we have here, while we're at it does anybody know why does solaris
have almost unusable utilities? grep that does not support -A -B -C
etc... they ship at least two set of utilities but even the better set
is quite bad... is it the compatibility? inertia?)

	erik

Carel Fellinger wrote:
> 
> 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
> 
> --
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null



Reply to: