.pyc files...

Nick Craig-Wood nick at craig-wood.com
Sun Nov 14 08:30:38 EST 2004


Eddie Parker <eddie at kickingdragon.com> wrote:
> Stephen Waterbury wrote:
> > alias cleanpy="find . -name '*.pyc' -exec rm {} ';'"
> > or with backticks:  rm -rf `find . -name '*.pyc'`
>  Hrmm, this is more a *NIX discussion, but I'm curious:
> 
>  That could be problematic if you have too many .pyc files found - overflow
>  the command buffer, no?
> 
>  Something like: "find . -name '*.pyc' | xargs -i rm -f {}", would solve
>  that, as xargs executes each encountered argument individually, I believe (I
>  think the -exec command does similar, in Stephen's original post).

the -exec will spawn rm for each file which is inefficient as will
your xargs solution.

However

  find . -name '*.pyc' | xargs rm -f

Just spawns one rm.  If the number of files gets too big for a command
line then xargs spawns another rm.

This isn't bullet proof though - consider what happens when you get
file names with 's in etc...

This *is* bullet proof though

  find . -name '*.pyc' -print0 | xargs -0 rm -f

And if you don't want an error when there aren't any files

  find . -name '*.pyc' -print0 | xargs -0r rm -f

End unix sysadmin lecture ;-)

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list