[clug] list only directories

Duncan Roe duncan_roe at acslink.net.au
Wed Nov 20 03:42:49 MST 2013


I've found this to work quite well:

find . -follow -maxdepth 1 -type d -print0 | sed s#[.]/##g | xargs -0 ls -d

Because of -follow, it does list symlinks pointing to directories. -print0 / -0
should list directories with spaces in their names, but I didn't check.

-F or -l will list symlinks as symlinks, unless you also use -L.

The sed command mangles the entries for . and ..

Cheers ... Duncan.

On Wed, Nov 20, 2013 at 05:37:50PM +1100, Eyal Lebedinsky wrote:
> Not answering the exact Q the OP asks (wanted 'ls' option), but once I need a selection I go for
> 'find' which was born to do this, like
> 	find . -maxdepth 1 -type d
> or
> 	find . -maxdepth 1 -type d -ls
> or even (for proper 'ls' formatting)
> 	ls `find . -maxdepth 1 -type d`
> and so on...
>
> cheers
> 	Eyal	
>
> On 11/20/13 17:22, Hal Ashburner wrote:
> >Dear Clug,
> >
> >To list only directories I have a one line script ~/bin/lsd [1]
> >
> >#!/bin/bash
> >ARG="${1:-.}"
> >\ls ${ARG} | while read a; do if [[ -d ${ARG}/${a} ]]; then echo ${a}; fi;
> >done
> >
> >so if i only want to see directories, that's what I see
> >
> >I've had it or something like it for years. Never given it much thought,
> >but it strikes me as really quite odd that ls, having 16536 different
> >options doesn't have one for just show me things of this type. Maybe I just
> >missed it? Reading manpages in depth is pretty painful.
> >
> >Do you good and talented people all do something similar? Are you doing
> >better? Have I missed a trick?
> >
> >Cheers,
> >
> >
> >
> >[1] it's called lsd as in ls for d - directories and in homage to the quip
> >about the two things that came out of Berkeley in the late 60s or early
> >70s, but has nothing whatever to do with ratpoison.
> >
>
> --
> Eyal Lebedinsky	(eyal at eyal.emu.id.au)
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux

--
 Please avoid sending me Word or PowerPoint attachments.
 See http://www.gnu.org/philosophy/no-word-attachments.html


More information about the linux mailing list