I'm trying to delete all files in a directory (recursively) with a name that contains a string. Ultimately I want to do this:
find . -type f -name '*.m3d*' -delete
But before running the delete, I tested if I'm finding all the files with this:
find . -type f -name '*.m3d*' but this returns an incomplete list:

./Result/h-field (f=15)_1,1.m3d  
./Result/e-field (f=15)_1,1.m3d
./Result/h-field (f=15)_2,1.m3d
./Result/e-field (f=15)_2,1.m3d  

The complete list can be see with this:
find . | grep m3d

./Result/e-field (f=15)_1,1_m3d.rex
./Result/h-field (f=15)_1,1.m3d
./Result/e-field (f=15)_1,1.m3d
./Result/h-field (f=15)_2,1_m3d.rex
./Result/e-field (f=15)_2,1_m3d.rex
./Result/h-field (f=15)_2,1.m3d
./Result/e-field (f=15)_2,1.m3d  

I read the man page for find and it says that a wildcard can't be used at the end of the string like I tried in my initial attempt. What would be a good way to delete all files that contain my string, but not necessarily at the end of the name?


1 Answer 1


I am not sure what version of find you are currently using, but I could not find any reference that the wildcard does not work at the end of the string.

Your issue appears to be how the files are named. The files not showing up in your search do not match *.m3d* as they do not have a dot (.) before the string m3d but an underscore (_) so find would not match them with the given criteria.

The command find . -type f -name '*m3d*' should be able to find all of those files from the given example.

  • well spotted... (or maybe I'm just blind)
    – ilkkachu
    Nov 22, 2022 at 19:23
  • Arggh. I'm stupid. I started the process matching *.m3d at the end and then forgot to get rid of the . when I was looking through the whole name. Yes *m3d* works as expected. Then I misread the find man page in the -name section. It mentions something about matching only at the begging of name, but that is referring to some metacharacters. Thanks for the help!
    – Sanjo
    Nov 22, 2022 at 20:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .