Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to remove all the .pyc files recursively from a certain directory including sub-directories? I tried

$rm -f *.pyc

This seems to work for only the current directory, but not the directories following it. Please help me..

share|improve this question

migrated from stackoverflow.com Nov 7 '12 at 13:59

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 1 down vote accepted

You can use

cd <your_directory>
find . -name "*.pyc" -exec rm '{}' ';

This will remove all the *.pyc files from your current directory and its sub directory

share|improve this answer
1  
I felt that this is a very simple command.. self explanatory.. –  Hisham Ibrahim Nov 7 '12 at 12:35
    
Why doesn't anyone think of using rm -rf *.pyc ? –  Nehal J. Wani Nov 10 '12 at 15:22

Use find:

find /some/directory -type f - name "*.pyc" -exec rm -f {} \;

or, if your find has the -delete option:

find /some/directory -type f - name "*.pyc" -delete
share|improve this answer
find /var/www/html -name "*.pyc" -delete
share|improve this answer
    
You need to quote *.pyc otherwise the shell will expand it. This will not work if there are pyc files in the base directory. –  dogbane Nov 7 '12 at 12:27
    
@dogbane thanks. added :) –  user868766 Nov 7 '12 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.