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

2021-01-18 Thread Paul Eggert

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.
>From eebed78799a7996dd80b66c493a0fc199705dea3 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Mon, 18 Jan 2021 21:08:39 -0800
Subject: [PATCH] doc: rmdir --recursive substitutes

* doc/coreutils.texi (rmdir invocation): Add note on how to remove
empty subdirectories recursively.
---
 doc/coreutils.texi | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index fe2fc52b7..94c9fbfa5 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11006,7 +11006,19 @@ Give a diagnostic for each successful removal.
 
 @end table
 
-@xref{rm invocation}, for how to remove non-empty directories (recursively).
+@xref{rm invocation}, for how to remove non-empty directories recursively.
+
+To remove all empty directories under @var{dirname}, including
+directories that become empty because other directories are removed,
+you can use either of the following commands:
+
+@example
+# This uses GNU extensions.
+find @var{dirname} -type d -empty -delete
+
+# This runs on any POSIX platform.
+find @var{dirname} -depth -type d -exec rmdir @{@} +
+@end example
 
 @exitstatus
 
-- 
2.27.0



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

2021-01-18 Thread Paul Eggert

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.






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

2021-01-18 Thread Pádraig Brady

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





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

2021-01-18 Thread Ulf Zibis



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






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

2021-01-18 Thread L A Walsh




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.










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

2021-01-18 Thread 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.



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.