Searching for specific files then delete them

Florian Diesch diesch at spamfence.net
Fri Sep 1 12:26:55 UTC 2006


Dennis Kaarsemaker <dennis at kaarsemaker.net> wrote:

> On di, 2006-08-29 at 14:24 +0100, Tony Arnold wrote:
>> > find . -name *~ | xargs rm
>> 
>> or
>> 
>> find . -name *~ -exec rm {} \;
>> 
>> The rm command gets executed for each file found and the {} is
>> substituted with the file name. The \; is necessary syntax to
>> terminate
>> the -exec option. 
>
> That's not an 'or', that's the correct way.
>
> The suggestion from Dieter will fail on filenames containing e.g.
> spaces.
>
> find . -name *~ -print0 | xargs -0 rm 
>
> works better, but find's -exec is really much better (if you quote the
> {} ;))

But then use
 -exec rm {} +
as with the "+" one rm call is used for as much files as possible (like
with xargs) instead of calling rm for every single file like with 
 -exec rm {} \;


   Florian
-- 
<http://www.florian-diesch.de/>




More information about the ubuntu-users mailing list