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

To reply to this bug, email your comments to 45924 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Sun, 17 Jan 2021 00:31:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to L A Walsh <coreutils <at> tlinx.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 17 Jan 2021 00:31:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: L A Walsh <coreutils <at> tlinx.org>
To: Coreutils <bug-coreutils <at> gnu.org>
Subject: 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?










Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Sun, 17 Jan 2021 22:20:02 GMT) Full text and rfc822 format available.

Message #8 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: L A Walsh <coreutils <at> tlinx.org>, 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Sun, 17 Jan 2021 14:18:58 -0800
On 1/16/21 4:29 PM, L A Walsh wrote:
> Yes, you could do it some other way, like by using 'find'

That's what I'd do, yes. 'find DIR -depth -type d -exec rmdir {} +'. I 
doubt whether it's worth hacking on this at the C level (complicating 
the documentation too) when there's such a simple and portable way to do 
this unusual task already.




Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Mon, 18 Jan 2021 10:55:01 GMT) Full text and rfc822 format available.

Message #11 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: L A Walsh <coreutils <at> tlinx.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 02:53:42 -0800
Except that 'find DIR -depth -type d -exec rmdir {} +'
is anything but simple and not something anyone outside of
a minority of *nix users would have a clue about how to 
create, whereas 'rmdir -r DIR' is both direct and simple and
more easily understandable by those who know how to remove
a directory and recursively remove files. Applying the -r
option of 'rm' and 'rd's focus on dirs seems a natural 
combination.


Gnu authors seem to pride themselves on their technical and
programming expertise (and not necessarily, w/o reason); but like
many high-level engineers, seem to lose touch with the concept of
'user-friendly' and often, it seems, tend toward the idea that the
users can and should adapt to the program(s) for the sake of
the programs (and engineers).  This is in contrast to the idea
of computers (and programs) being designed as tools to aid, assist,
simplify and empower those who use such tools.



On 2021/01/17 14:18, Paul Eggert wrote:
> On 1/16/21 4:29 PM, L A Walsh wrote:
>> Yes, you could do it some other way, like by using 'find'
> 
> That's what I'd do, yes. 'find DIR -depth -type d -exec rmdir {} +'. I 
> doubt whether it's worth hacking on this at the C level (complicating 
> the documentation too) when there's such a simple and portable way to do 
> this unusual task already.




Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Mon, 18 Jan 2021 16:10:02 GMT) Full text and rfc822 format available.

Message #14 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Paul Eggert <eggert <at> cs.ucla.edu>, L A Walsh <coreutils <at> tlinx.org>,
 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 17:08:51 +0100
On 1/17/21 11:18 PM, Paul Eggert wrote:
> find DIR -depth -type d -exec rmdir {} +

find(1) can also find empty directories and delete them:

  $ find DIR -type d -empty -delete

FWIW: -delete implies -depth.

If one wants to see what empty directories have been found (and get deleted),
just put a -print in there:

  $ find DIR -type d -empty -print -delete

The above works with GNU find (as both -empty and -delete are GNU extensions).

Have a nice day,
Berny




Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Mon, 18 Jan 2021 20:18:02 GMT) Full text and rfc822 format available.

Message #17 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: L A Walsh <coreutils <at> tlinx.org>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: Paul Eggert <eggert <at> cs.ucla.edu>, 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 12:15:26 -0800

On 2021/01/18 08:08, Bernhard Voelker wrote:

> find(1) can also ... [various examples of find's usefulness elided]
> Have a nice day,
> Berny
===
	As I stated in the original message:

On 2021/01/16 16:29, L A Walsh wrote:
> 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.

Thank you Bernhard, but numerous ways to do it with find don't 
really have the simplicity, of using "remove dir" for its
"raison d'être":

 rmdir -r DIR

 vs. find:

 find DIR -depth -type d -exec rmdir {} +


One could also use find to implement recursive file removal instead of
using 'rm', but that's hardly simple or straightforward as "rm -r"
either.









Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Mon, 18 Jan 2021 21:19:02 GMT) Full text and rfc822 format available.

Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ulf Zibis <Ulf.Zibis <at> gmx.de>
To: bug-coreutils <at> gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 22:05:40 +0100
Am 18.01.21 um 11:53 schrieb L A Walsh:
> Except that 'find DIR -depth -type d -exec rmdir {} +'
> is anything but simple and not something anyone outside of
> a minority of *nix users would have a clue about how to create, whereas 'rmdir -r DIR' is both direct and simple and
> more easily understandable by those who know how to remove
> a directory and recursively remove files. Applying the -r
> option of 'rm' and 'rd's focus on dirs seems a natural combination.

+1

Ulf





Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Mon, 18 Jan 2021 22:34:02 GMT) Full text and rfc822 format available.

Message #23 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: L A Walsh <coreutils <at> tlinx.org>,
 Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: Paul Eggert <eggert <at> cs.ucla.edu>, 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 22:33:36 +0000
On 18/01/2021 20:15, L A Walsh wrote:
> 
> 
> On 2021/01/18 08:08, Bernhard Voelker wrote:
> 
>> find(1) can also ... [various examples of find's usefulness elided]
>> Have a nice day,
>> Berny
> ===
> 	As I stated in the original message:
> 
> On 2021/01/16 16:29, L A Walsh wrote:
>> 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.
> 
> Thank you Bernhard, but numerous ways to do it with find don't
> really have the simplicity, of using "remove dir" for its
> "raison d'être":
> 
>    rmdir -r DIR
> 
>    vs. find:
> 
>    find DIR -depth -type d -exec rmdir {} +
> 
> 
> One could also use find to implement recursive file removal instead of
> using 'rm', but that's hardly simple or straightforward as "rm -r"
> either.

`rmdir -r` does have some merit.
However the key thing here is it's an unusual operation.
Also there is a way to achieve it with a single existing command.
Comparing with `rm -r` is not equivalent as that's a vastly more common operation.
Also that has overlaps with other functionality like prompting etc.

So I'd be 70:30 against adding `rmdir -r`

cheers,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Tue, 19 Jan 2021 05:17:01 GMT) Full text and rfc822 format available.

Message #26 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: L A Walsh <coreutils <at> tlinx.org>
Cc: 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 21:16:03 -0800
On 1/18/21 2:53 AM, L A Walsh wrote:
> Except that 'find DIR -depth -type d -exec rmdir {} +'
> is anything but simple and not something anyone outside of
> a minority of *nix users would have a clue about how to create, whereas 
> 'rmdir -r DIR' is both direct and simple and
> more easily understandable

It's not that simple. For example, it's not clear whether rmdir -r 
should also remove directories containing only empty subdirectories, 
which is what you asked for. Perhaps some people would want that, 
perhaps they'd want to remove just empty leaf directories. Or perhaps 
they'd want rmdir to remove empty subdirectories only if it has 
permission to do so. Or maybe they'd want to also remove subdirectories 
whose directory entries are all hidden (start with '.'). Or there are 
lots of other possible things people could plausibly want.

This is what 'find' is for. If people needed to do something like "rmdir 
-r" every day then it'd be plausible to add it even though there's a 
simple substitute. But people don't, so let's stick with what we have.




Information forwarded to bug-coreutils <at> gnu.org:
bug#45924; Package coreutils. (Tue, 19 Jan 2021 05:19:01 GMT) Full text and rfc822 format available.

Message #29 received at 45924 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>,
 L A Walsh <coreutils <at> tlinx.org>, 45924 <at> debbugs.gnu.org
Subject: Re: bug#45924: RFE: rmdir -r: recursively remove [empty] directories
 under the target.
Date: Mon, 18 Jan 2021 21:18:09 -0800
[Message part 1 (text/plain, inline)]
On 1/18/21 8:08 AM, Bernhard Voelker wrote:
> On 1/17/21 11:18 PM, Paul Eggert wrote:
>> find DIR -depth -type d -exec rmdir {} +
> 
> find(1) can also find empty directories and delete them:
> 
>    $ find DIR -type d -empty -delete

Thanks, I'd forgotten about that.

I added the attached to the manual, as the point seems worth documenting 
even if we don't change the code.
[0001-doc-rmdir-recursive-substitutes.patch (text/x-patch, attachment)]

Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 21 Feb 2022 10:08:01 GMT) Full text and rfc822 format available.

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

Previous Next


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