Frost Frost - 17 days ago 10
Bash Question

removing some files out of several folders

I have a question about removing some files out of several folders.
To be more specific: There are 5 Folders which are only the same by a few characters. For example: o1_FolderF_xy and zz_FolderF_34. And in each folder with the characters "FolderF" I want to delete all the files which starts with "filename".

The last time I did it by hand.
Will this work? Or do i need a script with a loop?

rm -rf /path/toFolder/*FolderF*/filename*


I'm sorry, I think for most it's a stupid question. But I'm new to all the stuff and I just do not want to go wrong with the delete

Answer Source

You could use find instead:

find /path -name 'filename*' -exec rm {} \;

Basically it search's files with filename pattern on /path directory and for each file it executes rm.

Or, if you want to just check into those specific directories:

find /path -wholename '*folder*/filename*' -exec rm {} \;