[clug] list only directories

Hal Ashburner hal at ashburner.info
Wed Nov 20 00:23:54 MST 2013


Just also noticing that
find . -maxdepth 1 -type d -print
also excludes symlinks to directories, that you probably want to treat as
directories and list as such.
where
test -d symlink_to dir
returns true.

Do we seem to be agreeing that on unix, ls is actually a bit broken? Anyone
take issue with that statement?



On 20 November 2013 17:54, steve jenkin <sjenkin at canb.auug.org.au> wrote:

> Hal Ashburner wrote on 20/11/13 5:22 PM:
>
> > Do you good and talented people all do something similar? Are you doing
> > better? Have I missed a trick?
>
> Hal,
>
> you've missed nothing.
> 'ls' doesn't let you get to a bunch of useful metadata in the inode, as
> well being deficient in options and annoying 'user readable' variable
> formatting (Grrrr).
> This gave PERL a kick along as the SysAdmin's Swiss Army Chainsaw. It
> allows scripts to retrieve and work with actual metadata, fully accessible.
>
> ==> this should be a robust solution to what you want to do.
> [Andrew J, please correct/improve!]
>
> find . -maxdepth 1 -type d -print0|xargs -0 ls -ld
>
> - look in current dir
> - no need for 'nofollow' (symlinks) or -xdev
> - maxdepth is current dir
> - type d, vs type f, l, ...
> - print args with nul ('\0x0') chars, not newlines
> - use xargs to do its thing reliably.
>
> You'll all laugh, I only recently realised that:
>
> find . -type f | tr '\n' '\0'
>
> was equivalent to
> find . -type f -print0
>
> Useful when you capture a list of files & do some normal
> editing/selection on them, then you can still use xargs.
>
> [I've another problem with using xargs and 'mv'. You have to work hard
> to put the new destination at the end of the line, after the args that
> xargs inserts. Or I should reread the man pages :)]
>
> In early V6/7 & BSD systems, filenames didn't have shell "word breaks"
> or special characters.
> find didn't need -print0, filenames didn't confuse the shell.
>
> I can't recall the MAXPATH (?) and max dirent size, but they were small.
> 14 chrs in V6 [and 16-bit inodes in ufs] springs to mind.
>
>
> cheers
> steve
> --
> Steve Jenkin, Info Tech, Systems and Design Specialist.
> 0412 786 915 (+61 412 786 915)
> PO Box 48, Kippax ACT 2615, AUSTRALIA
>
> sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux
>


More information about the linux mailing list