zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@sunsite.dk
Subject: Re: Finding empty directories
Date: Thu, 23 Oct 2003 20:16:30 +0200	[thread overview]
Message-ID: <20031023181630.GI52@DervishD> (raw)
In-Reply-To: <1031023174025.ZM6878@candle.brasslantern.com>

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> [My ISP had a "latency problem" (their words)

    Sorry :((( I've had problems with email, too, and its *very*
annoying...

> >     I want to test if a directory is empty or not and I've thought
> > that I could test for the expansion of dirname/*(DN[1]).
> >     Anyway I was wondering if is there a better way of doing that
> 	dirname(N-/l2)

    I tried that too, but it doesn't work, because under Linux,
directories with just files on them seems to have only two links :(
Don't know if this is a problem of the filesystem (ext3) or if this
is the standard Unix behaviour...

    To my knowledge, and empty dir has only two hardlinks: the '.'
and the '..' entries :?? But anyway, using stat on empty dirs and on
dirs with just files in it, gives me 'nlink' as '2' :((
 
> In some older versions of zsh you may need to do something funky to get
> the parenthesized part to be interpreted as glob qualifiers, because in
> those versions qualifiers are interpreted only when a metacharacter is
> part of the pattern.

    I'm using 4.0.7 right now, so this is not a problem.
 
> >     I would like to test if a filename correspond to a dangling
> > symlink, too. I can find dangling symlinks using **/*(-@), but if I
> > just have a file listing, how can I test if a file is a dangling
> > symlink or not?
> What do you mean by "just have a file listing"?  Except as noted above for
> older versions, you can always append a glob qual, as in file(N-@).

    A generated list of files in a file, for example, which I must
examine entry by entry. Obviously I didn't know that you can append a
glob qual even if no glob metachar is present O:)) I did a quick and
dirty test that failed (a typo, obviously) and I thought that it
couldn't be done at all. My fault, sorry O:)))

> > I've found that doing the following test:
> >     [[ -h file && ( -r file || -d file ) ]]
> Yes, -r and -d use stat(2) rather than lstat(2), but you probably want
> 	[[ -h file && ( -f file || -d file ) ]]

    Yes, true, just a typo O:))
 
> You could also do something like
> 	zmodload zsh/stat
> 	{ stat +link bar && ! stat +nlink bar 2>/dev/null } >/dev/null

    Yes, I know, but I wanted to avoid depending on zsh/stat module,
although it is not an issue.

    Thanks a lot :)))

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


  reply	other threads:[~2003-10-23 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-23 17:40 Bart Schaefer
2003-10-23 18:16 ` DervishD [this message]
2003-10-24 14:44   ` Bart Schaefer
2003-10-25 17:55     ` DervishD
  -- strict thread matches above, loose matches on Subject: below --
2003-10-23 15:35 DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031023181630.GI52@DervishD \
    --to=raul@pleyades.net \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).