to grep and rm including all subdirectories

Is there a way to grep a word pattern in all files under all subdirectories?

Similar question with rm. To remove files with certain extension in all subdirectories?

Thanks to all who reply!

Yes, of course. The way I do this is with the find() command. For example, to remove all mp3 files in a directory and all subdirectories;

find * -regex '.*\.mp3' -exec rm {} ;

This will recursively find all files and use the regular
expression matching any string up to the final .mp3
and then remove that file (might want to check the regex
pattern, I'm doing this without checking :slight_smile:

Another example. You want to change the owner and group
of all files and subfiles:

find * -exec chown admin.users {} \;

My suggestion is that you do a 'man on find' and read about using the -regex and -exec flags. Fun and powerful stuff!