bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Bernhard Voelker
Subject: bug#32843: Feature request: rm -ir variant not asking about directories
Date: Wed, 26 Sep 2018 20:39:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]