From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13536 invoked from network); 23 Oct 2003 17:40:58 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 23 Oct 2003 17:40:57 -0000 Received: (qmail 2237 invoked by alias); 23 Oct 2003 17:40:28 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6732 Received: (qmail 2193 invoked from network); 23 Oct 2003 17:40:28 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 23 Oct 2003 17:40:28 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [4.3.58.249] by sunsite.dk (MessageWall 1.0.8) with SMTP; 23 Oct 2003 17:40:27 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id h9NHeQS06879 for zsh-users@sunsite.dk; Thu, 23 Oct 2003 10:40:26 -0700 From: Bart Schaefer Message-Id: <1031023174025.ZM6878@candle.brasslantern.com> Date: Thu, 23 Oct 2003 17:40:25 +0000 X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: Finding empty directories MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii [My ISP had a "latency problem" (their words) with mail servers from late yesterday evening (PST) until a few minutes ago this morning. I may have lost some mail as a result, or it may be sitting in queues at the sending machines waiting to be delivered. I'm responding to this one by cutting and pasting from the archives. Oh -- there's the original, just as I was about to send ...] > 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) (That's "ell two" as in "link count is two".) I suppose if you already know it is a directory, the (/) is redundant. 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 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-@). > I've found that doing the following test: > > [[ -h file && ( -r file || -d file ) ]] > > will only return true for a symlink that really points to a file > or a directory, and false otherwise, but I'm not sure if this is a > proper way or if it will fail miserably on some obscure case :? In > fact, I'm not sure if '-r' and '-d' follow symlinks by default :? Yes, -r and -d use stat(2) rather than lstat(2), but you probably want [[ -h file && ( -f file || -d file ) ]] You could also do something like zmodload zsh/stat { stat +link bar && ! stat +nlink bar 2>/dev/null } >/dev/null