Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove all files with some extension from directories and subdirectories

Tags:

bash

rm

Why does command:

rm **/*.pyc

removes nothing?

What is the proper way to achieve expected behavior?

like image 257
kharandziuk Avatar asked Oct 17 '25 15:10

kharandziuk


1 Answers

To make your command work, you need to enable globstar first:

shopt -s globstar

When globstar mode is enabled, **/*.pyc will expand to match files ending in .pyc in the current directory and all subdirectories.

Alternatively you could just use find:

find -name "*.pyc" -delete

This will search for anything ending in .pyc in the current directory and all subdirectories, deleting whatever it finds. To restrict it to only match files, you can add the -type f switch as well, although this may not be a problem (and wouldn't have been the case in your original command).

Or, if your version of find doesn't understand -delete:

find -type f -name "*.pyc" -exec rm {} \;
like image 85
Tom Fenech Avatar answered Oct 19 '25 04:10

Tom Fenech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!