Remove Files Recursively in Linux

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

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

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.