Deleting directories
Evelyn C. Leeper
ecl at cbnewsj.att.com
Tue Jul 10 23:05:48 AEST 1990
In article <37481 at ucbvax.BERKELEY.EDU> ashish at 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 at mtgzy.att.com
--
The only thing necessary for the triumph of evil is for good men to do nothing.
-Edmund Burke
More information about the Comp.unix.questions
mailing list