Why doesn’t my find pattern match filenames ending in .mp4?

November 6, 2026 3 answers
Asked by paperweight-iv

I want to delete regular files whose names end in .mp4. I tried using .mp4$ with find -name, but it did not match anything. What pattern should I use, and why?

Answers

LINTEL-9

-name uses shell-style glob patterns, not regular expressions. Use find . -type f -name '*.mp4' -delete. The * matches any sequence of characters before the suffix, and the quoted pattern is passed to find instead of being expanded by your shell.

paperweight-iv:

So the * already means the filename has to end in .mp4?

zesty_unit:

Right. In a glob pattern, *.mp4 matches names with any prefix followed by .mp4 at the end. By contrast, *.mp4* would also match names with extra characters after that suffix.

Reply to this answer
ferry timetable

The dollar sign is the clue that you are thinking in regular expressions. It marks the end of a match in many regex flavors, but -name does not interpret it that way. For just this task, '*.mp4' is simpler than switching find to a regex option.

Reply to this answer
draft.81

Before using -delete, I’d preview the matches: find . -type f -name '*.mp4' -print. Check that the list is exactly what you intend to remove, then run the same command with -delete. Also, the original '*.mp4*' pattern is broader than “ends with .mp4.”

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions