du0r7q
Last Updated: February 25, 2016
·
5.247K
· nahimnasser
D36e518035e3ca650a8d8014a671355b

Remove all .pyc files from a directory

In the terminal, navigate to your folder and type the following command to remove all pyc files from that directory and its subdirectories:

find . -name "*.pyc" -exec rm -rf {} \;

Also on Ubuntu, you can try pyclean (comes pre-installed):
http://manpages.ubuntu.com/manpages/precise/man1/pyclean.1.html

Say Thanks
Respond

4 Responses
Add your response

8650
Ab927485bccfcf35ba4583723876063f

Just a small note, it is only called ‘folder’ on Windows, on Linux we call it ‘directroy’ or sometimes ‘catalogue’ (US: catalog).

Also why do a recursive or even a forced removal?

over 1 year ago ·
8690
D36e518035e3ca650a8d8014a671355b

Good catch on the nomenclature ---

A recursive removal will clear up any .pyc files in subdirectories.

over 1 year ago ·
8730
Ab927485bccfcf35ba4583723876063f

No, that is that find is for, -r will remove any file including directoried named with .pyc at the end.

over 1 year ago ·
8771
6f4937be9744216af8fe766ae9cac79f

Deleting with find is common, so there's a shortcut:
find . -name "*.pyc" -delete

I will have to check out pyclean. Thanks for the tip.

over 1 year ago ·
Filed Under