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

Re: Why has "find ... -exec rm -i '{}' ';'" stopped working?



> On Tue, Jul 05, 2005 at 05:51:07AM -0400, Andrew Schulman wrote:
> 
>> find ... -print0 | xargs -0r rm -i
> 
> This won't work because rm -i reads for confirmation from stdin and rm
> has no stdin when it's run via xargs.

Hm, you're right.  Well one alternative that will definitely work is

find ... -ok rm '{}' ';'

but this looks different to the user and so may be less desirable.
Another alternative that's more complicated, but will work (if you're
using bash) and look the same to the user is

eval files=\( $(find ... -printf \"%p\"\ )\)
if [ $files ] ; then
  rm -i "${files[@]}"
fi

Here files is a shell array of file names.  The "eval" and -printf force
there to be exactly one array element for each file name, even if some
file names include white space.  They will fail, however, if a file name
has a double-quote in it.



Reply to: