Unix magic, delete all .pyc files from a tree of directories?

Is there a quick way of deleting all the .pyc files from a tree of directories?


If you've got GNU find then you probably want

find <directory name> -name '*.pyc' -delete

If you need something portable then you're better off with

find <directory name> -name '*.pyc' -exec rm {} \;

If speed is a big deal and you've got GNU find and GNU xargs then

find <directory name> -name '*.pyc' -print0|xargs -0 -p <some number greater than 1> rm

This is unlikely to give you that much of a speed up however, due to the fact that you'll mostly be waiting on I/O.


using the command find:

find /path/to/start -name '*.pyc' -exec rm -f {} \;

cd to the start of the tree of directories then:

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