bug-coreutils
[Top][All Lists]
Advanced

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

Re: Feature request: rm should implement option -p, --parents


From: Jim Meyering
Subject: Re: Feature request: rm should implement option -p, --parents
Date: Tue, 07 Jul 2009 08:48:52 +0200

Guido Flohr wrote:
> Hi Pádraig,
>
> Pádraig Brady wrote:
>>> Uninstalling with clean up in such cases is a frequent task, and could be 
>>> greatly simplified by:
>>>
>>>     $ rm --parents /usr/share/myapp/pixmaps/8x16/icon.png
>>>     rm: failed to remove `/usr/share': Directory not empty
>>>     $ ls /usr/share/myapp
>>>     ls: cannot access /usr/share/myapp: No such file or directory
>>>
>>> The idea is to remove the containing directory of a file recursively, 
>>> upwards, and stop that recursion on the first failure to remove a 
>>> directory, most probably because of ENOTEMPTY.
>>
>> Would that not be better supported with:
>>
>> rm "$dir/icon.png" && rmdir -p "$dir"
>>
>> I can kind of see the benefit of your proposal in the
>> unusual case where $dir is not known. But then one can do:
>>
>> rm "$file" && rmdir -p $(dirname "$file")
>
> Sure.  But compare that to:
>
>     rm -p $file
>
> Clearer and more efficient to boot.

It is hard to justify adding an option to GNU rm when you can get
the desired functionality via a tiny shell script:

#!/bin/bash
fail=0
for f in "$@"; do
  unlink "$f" || { fail=1; continue; }
  parent=$(dirname "$f")
  rmdir -p "$parent" || fail=1
done
exit $fail




reply via email to

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