Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!att!cbnewsj!ecl From: ecl@cbnewsj.att.com (Evelyn C. Leeper) Newsgroups: comp.unix.questions Subject: Re: Deleting directories Message-ID: <1990Jul10.130548.10216@cbnewsj.att.com> Date: 10 Jul 90 13:05:48 GMT References: <37481@ucbvax.BERKELEY.EDU> Organization: AT&T Bell Laboratories Lines: 20 In article <37481@ucbvax.BERKELEY.EDU> ashish@janus.Berkeley.EDU.UUCP (Ashish Mukharji) writes: > Recently, I had to remove all of a user's files older than a > certain date. That was easily accomplished with find(1), but deleting the > resulting (empty) directory structure presents a greater problem. The user's > home directory is the root of a large, mostly empty directory tree. I want > to delete all directories that do not contain any regular files - find starts > with . and works its way down (inorder). What I need is a way to do a > postorder traversal of the directory structure. Is there a simple way, short > of writing a C routine? I should say RTFM, but: find top-directory-name -depth -type d -exec rmdir {} \; The -depth goes postorder. The rmdir will fail on any non-empty directories. Evelyn C. Leeper | +1 201-957-2070 | att!mtgzy!ecl or ecl@mtgzy.att.com -- The only thing necessary for the triumph of evil is for good men to do nothing. -Edmund Burke