From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21916 invoked from network); 23 Oct 2003 18:44:34 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 23 Oct 2003 18:44:34 -0000 Received: (qmail 9528 invoked by alias); 23 Oct 2003 18:44:17 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6733 Received: (qmail 9466 invoked from network); 23 Oct 2003 18:44:17 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 23 Oct 2003 18:44:17 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [62.193.203.32] by sunsite.dk (MessageWall 1.0.8) with SMTP; 23 Oct 2003 18:44:16 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id h9NIi9106748; Thu, 23 Oct 2003 20:44:09 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1ACk0c-0003GI-00>; Thu, 23 Oct 2003 20:16:30 +0200 Date: Thu, 23 Oct 2003 20:16:30 +0200 From: DervishD To: Bart Schaefer Cc: zsh-users@sunsite.dk Subject: Re: Finding empty directories Message-ID: <20031023181630.GI52@DervishD> Mail-Followup-To: Bart Schaefer , zsh-users@sunsite.dk References: <1031023174025.ZM6878@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1031023174025.ZM6878@candle.brasslantern.com> User-Agent: Mutt/1.4i Organization: Pleyades User-Agent: Mutt/1.4i Hi Bart :) * Bart Schaefer 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/