[plug] deleting stuff in batches

Richard Meyer meyerri at westnet.com.au
Fri Nov 11 13:03:40 WST 2005


On Fri, 2005-11-11 at 09:21 +0800, Russell Steicke wrote:
> On Thu, Nov 10, 2005 at 09:34:33PM +0800, Stuart Midgley wrote:
> > find . -name "*.wma" -exec rm {} \;
> 
> That will work, but slowly if there are many files, as it will exec()
> /bin/rm once for each file.  A quicker way:
> 
>   find . -name '*.wma' -print0 | xargs -0 rm
> 
"man find" also says that find . -name '*.wma' -delete 
will work.

Whether that is faster than the xargs way, I don't know, but I suspect
it gets called once per file, but it may not have the overhead of the
"exec".

It also says that find . -name "*.wma" -exec rm {} +
will work.
from the man page:

> -exec command {} +
>               This  variant  of the -exec option runs the specified command on
>               the selected files, but the command line is built  by  appending
>               each  selected file name at the end; the total number of invoca‐
>               tions of the command will  be  much  less  than  the  number  of
>               matched  files.   The command line is built in much the same way
>               that xargs builds its command lines.  Only one instance of  '{}'
>               is  allowed  within the command.  The command is executed in the
>               starting directory.

That's one of the nice things about Unix/Linux - "There's always another way".

Thought I'd add these in in case you were "insufficiently confused", and
since I went to read the man page for xargs, which made me read the man
page for find, I thought I'd show off my new education. ;-)

-- 
Richard Meyer <meyerri at westnet.com.au>
"But the fact that some geniuses were laughed at does not 
 imply that all who are laughed at are geniuses. They laughed 
 at Columbus, they laughed at Edison, they laughed at the 
 Wright brothers but they also laughed at Bozo the Clown.
            -- Carl Sagan

Linux Counter user #306629




More information about the plug mailing list