I have some photos named like this: photo_1@15-05-2018_18-49-14.png

But I only want to delete files with ending with _thumb.png, like photo_1@15-05-2018_18-49-14_thumb.png

All of them are in different directories too

How would I delete all files ending with _thumb.png in the Linux shell? (I can't use file explorer cause it keeps crashing; there are just thousands of files with _thumb in their name).

2 Answers 2

find . -type f -name '*_thumb.png' -exec rm -f {} +

This would call rm -f on batches of regular files whose names matches the pattern *_thumb.png. The files will be found in the current directory or in any of its subdirectories, or below.

If you have GNU find, or a find implementation that implements the -delete action (which you would likely have on Linux), you could instead use the slightly shorter

find . -type f -name '*_thumb.png' -delete

Insert -print before -delete (or -exec) to also get a listing of the pathnames that are removed.


It is

rm -r *_thumb.png

Thanks to a friend for answering that.

  • This would still only affect names matching that pattern in the current directory.
    – Kusalananda
    Jun 12, 2020 at 6:45
  • And if you have thousands of these files, you will probably exceed the permitted size of the args to rm. Cultivate your circle of friends. Jun 12, 2020 at 9:22

You must log in to answer this question.

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