GNU bug report logs - #32843
Feature request: rm -ir variant not asking about directories

Previous Next

Package: coreutils;

Reported by: nisse <at> lysator.liu.se (Niels Möller)

Date: Wed, 26 Sep 2018 09:20:02 UTC

Severity: wishlist

Full log


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

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Niels Möller <nisse <at> lysator.liu.se>, 32843 <at> debbugs.gnu.org
Subject: Re: bug#32843: Feature request: rm -ir variant not asking about
 directories
Date: Wed, 26 Sep 2018 20:39:01 +0200
On 9/26/18 11:19 AM, Niels Möller wrote:
> I have a large directory tree where most but not all directories are
> empty, and where I might want to keep a few of the existing files.
> 
> I can use rm -ir to get rm to ask me for each file if it should be
> deleted. But it also asks questions like
> 
>   rm: descend into directory 'foo'?
>   rm: remove directory 'foo'?
> 
> to which I'd always say yes (and then attempts to delete any non-empty
> directory fails with a clear warning message).
> 
> It would be less tedious if the questions about directories were
> suppressed. A reasonable command line flag might be 
> 
>   --interactive=non-dir
> 
> (If there are any entries which are niether files nor directories, e.g,
> a named pipe, I'd want rm to ask, hence "non-dir" rather than "file").
> 
> Another variant which would be useful is to traverse a directory tree
> and recursively delete all empty directories, without asking any
> questions. Would make sense as a --recursive/-r flag to rmdir, rather
> than a new option to rm.
> 
> I'm using GNU coreutils 8.28, which doesn't seem to have these features.

This report includes several aspects.  What exactly do you want to achieve?

If it is simply deleting all empty directories beneath DIR, then this can
already be achieved with existing tools/options:

  # Prepare some directories in DIR: a/a/a, a/a/c, ..., c/c/c.
  $ mkdir -p DIR/{a..c}/{a..c}/{a..c}

  # Place a file in each dir level,
  $ touch DIR/a/f DIR/b/a/f DIR/c/a/a/f

  # Delete all empty directories
  $ find DIR -depth -type d -empty -delete

  # See what's left:
  $ find DIR | xargs ls -ldog
  drwxr-xr-x 5 4096 Sep 26 20:33 DIR
  drwxr-xr-x 2 4096 Sep 26 20:33 DIR/a
  -rw-r--r-- 1    0 Sep 26 20:33 DIR/a/f
  drwxr-xr-x 3 4096 Sep 26 20:33 DIR/b
  drwxr-xr-x 2 4096 Sep 26 20:33 DIR/b/a
  -rw-r--r-- 1    0 Sep 26 20:33 DIR/b/a/f
  drwxr-xr-x 3 4096 Sep 26 20:33 DIR/c
  drwxr-xr-x 3 4096 Sep 26 20:33 DIR/c/a
  drwxr-xr-x 2 4096 Sep 26 20:33 DIR/c/a/a
  -rw-r--r-- 1    0 Sep 26 20:33 DIR/c/a/a/f

WRT changing the prompting  in rm: IMO the existing functionality is already
quite complex, so adding more complexity and even an option needs some good
justification.

Have a nice day,
Berny




This bug report was last modified 6 years and 263 days ago.

Previous Next


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