From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7311 invoked from network); 29 Mar 2004 13:29:44 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 29 Mar 2004 13:29:44 -0000 Received: (qmail 21911 invoked by alias); 29 Mar 2004 13:29:20 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7293 Received: (qmail 21898 invoked from network); 29 Mar 2004 13:29:18 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 29 Mar 2004 13:29:18 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 29 Mar 2004 13:29:17 -0000 Received: (qmail 6051 invoked from network); 29 Mar 2004 13:29:17 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 29 Mar 2004 13:29:15 -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 i2TDSgD24484; Mon, 29 Mar 2004 15:28:46 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1B7wo4-0001vL-00>; Mon, 29 Mar 2004 15:28:00 +0200 Date: Mon, 29 Mar 2004 15:28:00 +0200 From: DervishD To: Aaron Davies Cc: Aaron Davies , zsh-users@sunsite.dk Subject: Re: Globbing for Empty Directories? Message-ID: <20040329132800.GA7384@DervishD> Mail-Followup-To: Aaron Davies , Aaron Davies , zsh-users@sunsite.dk References: <20040328194921.GA6311@DervishD> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.1 required=6.0 tests=MAILTO_TO_SPAM_ADDR autolearn=no version=2.63 X-Spam-Hits: 1.1 Hi Aaron :) * Aaron Davies dixit: > >>Is there a way to get empty directories from a glob pattern? > >>'*(L0)' finds empty files, but doesn't work for dirs. I'm looking > >>for something the equivalent of find's -empty argument, since I > >>hate find with a passion and would love to never use it again. > > There is not, AFAIK. See the mailing list archives, I asked more > >or less the same a few months ago. Testing for the number of links > >won't work for directories :(( > Actually, I'm not sure of that. According to the info page for find, a > directory will always have two hard links, itself and it's "." pointer. That's true. > Adding any subdirectories or files to it seems to increase the number > of links it has. Not under Linux, at least, although it may depend on the filesystem type. For ext3, only subdirs increase the number of links of a directory. > So wouldn't *(/l2) find empty directories? It will find directories without subdirectories. > Or is this hard-link policy not true on all systems? I have not tested in many systems, but Linux don't do it, and I've not found any standard that require files to be links on the directory. If you find any, please tell me to report the current behaviour as a bug to Linux kernel developers, but looking at findutils sources (that being GNU are intended to be very portable), you can see the following: { if (S_ISDIR (stat_buf->st_mode)) { DIR *d; struct dirent *dp; boolean empty = true; errno = 0; d = opendir (rel_pathname); if (d == NULL) { error (0, errno, "%s", pathname); exit_status = 1; return (false); } for (dp = readdir (d); dp; dp = readdir (d)) { if (dp->d_name[0] != '.' || (dp->d_name[1] != '\0' && (dp->d_name[1] != '.' || dp->d_name[2] != '\0'))) { empty = false; break; } } if (CLOSEDIR (d)) { error (0, errno, "%s", pathname); exit_status = 1; return (false); } return (empty); } else if (S_ISREG (stat_buf->st_mode)) return (stat_buf->st_size == 0); else return (false); } This is the code for '-empty', and as you can see, it examines the files in the directory, not the number of links it has. Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/