Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dgcad!dg-rtp!larrybud.rtp.dg.com!goudreau From: goudreau@larrybud.rtp.dg.com (Bob Goudreau) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <1991Apr4.184259.16521@dg-rtp.dg.com> Date: 4 Apr 91 18:42:59 GMT References: <1991Mar30.040400.13893@ncsu.edu> <1991Mar30.225406.20493@dg-rtp.dg.com> <1991Apr3.142150.4445@athena.mit.edu> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: goudreau@larrybud.rtp.dg.com (Bob Goudreau) Organization: Data General Corporation, Research Triangle Park, NC Lines: 41 In article <1991Apr3.142150.4445@athena.mit.edu>, jik@athena.mit.edu (Jonathan I. Kamens) writes: > In article <1991Mar30.225406.20493@dg-rtp.dg.com>, hunt@dg-rtp.rtp.dg.com (Greg Hunt) writes: > |> If the directory size > |> is zero, then the directory is empty. Otherwise, it contains some > |> files. You should check this out on your system to make sure it holds > |> true for the flavor of UNIX that you're using. > > Um, I can't imagine this being true for *any* remotely normal > flavor of Unix.... > How can the directory be empty when it > has to store entries for "." and ".." in it? Because the directory does not *have* to store entries for "." and ".." in it. That's just an implementation detail; various UNIXes choose to implement things differently. Remember, POSIX.1 doesn't require anything particular about the implementation of directories; only the *interfaces* are specified (readdir, mkdir, etc.). Greg's example was on a system running DG/UX, which happens to implement directory files by keeping "." and ".." info in the inode itself. The implementation is unimportant, however -- all the standard interfaces (POSIX.1's readdir(), SVR4's getdents(), etc.) all return "." and ".." info as if there actually were on-disk entries for those names. As Greg noted, check your system's documentation if you are interested in the details of implementation. > In the second case, the directory did not shrink when the files were > deleted. Directories grow. I'm not even convinced that fsck shrinks > empty dirctories; I believe the only way to shrink a directory with > lots of empty entries in it is to create a new directory, mv the > files from the old directory into the one one, and remove the old > directory. Again, this sort of behavior is implementation-specific. Check your system documentation. DG/UX happens to be able to shrink directories dynamically; other systems differ. ---------------------------------------------------------------------- Bob Goudreau +1 919 248 6231 Data General Corporation goudreau@dg-rtp.dg.com 62 Alexander Drive ...!mcnc!rti!xyzzy!goudreau Research Triangle Park, NC 27709, USA