Remove files recursively in Linux

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..

3 Answers

You can use

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

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

3

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
find /var/www/html -name "*.pyc" -delete
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like