I was just handed a directory with some 40,000+ images, and the directory includes three versions of every file, which makes it a bear to have to transfer between servers.
I'm looking for a way using bash (OSX Terminal) to find and remove (rm) all files, for example, with _web, or _thumb on the end of the filename, just before the .jpg (or .gif, or .png, or .bmp, etc.) extension.
So, to be clear, I have the following files:
1.jpg
1_web.jpg
1_thumb.jpg
2.gif
2_web.gif
2_thumb.gif
etc.
And I only want "1.jpg", "2.gif", etc. to remain.
I've been able to rename extensions in the past, but my command-line-fu is pretty weak, and I'm at my wits end trying to figure out something that's reusable (I'm going to need to do this a couple times, as I'm working on a continuous migration script for this project).
Edit: After a bit more work on this, I found a few odd limitations of rm and xargs that I had to work around. I basically adapted the accepted answer below and ended up with:
$ find . -name '*_thumb.*' -print0 | xargs -0 rm -f
$ find . -name '*_web.*' -print0 | xargs -0 rm -f
Now I'm down to about 10,000 files - quite a savings in terms of pushing files around on the web!