GNU bug report logs - #45924
RFE: rmdir -r: recursively remove [empty] directories under the target.

Previous Next

Package: coreutils;

Reported by: L A Walsh <coreutils <at> tlinx.org>

Date: Sun, 17 Jan 2021 00:31:01 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: L A Walsh <coreutils <at> tlinx.org>
To: 45924 <at> debbugs.gnu.org
Subject: bug#45924: RFE: rmdir -r: recursively remove [empty] directories under the target.
Date: Sat, 16 Jan 2021 16:29:15 -0800
Every once in a while, I want to remove what I believe to be
an empty directory tree, safely.

I wondered, why not have rmdir have a recursive option
that would remove all directories under a given directory,
presuming they were empty.  That way I can try to remove
the tree, removing what it can, and only failing if it
ran into a file that prevented the removal.

I'd _at least_, have it do a depth-first removal and halt
with a ENOTEMPTY status if an rmdir failed to remove a
directory due to it not being empty.

So for dirs one,two,three + file dir 'two' next to three:

one-+two-+three
        |-file

rmdir -r one  would first remove
one/two/three,
then fail removing one/two because 'two wasn't empty'.

--- probably, I think adding a mode like "--failearly"
should also be available to have rmdir fail on the recursive
descent if it encountered non-dir while descending.

Yes, you could do it some other way, like by using 'find',
but since it is about removing directories, having the option
under rmdir would seem a natural place to put it.

Useful?










This bug report was last modified 3 years and 116 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.