How to Find and Replace Text in Filenames on Mac
Find and replace is the most common batch rename operation. Replacing a word, removing a prefix, or swapping one string for another across hundreds of files saves hours of manual renaming. macOS provides three approaches: Finder for simple replacements, Terminal for scripted operations, and Batchio for visual workflows with live preview.
How Do You Find and Replace in Filenames Using Finder?
Finder's Replace Text mode is the fastest way to perform a simple text substitution across multiple files on macOS. No additional software is needed. The operation supports replacing any text string with any other string, including replacing text with nothing (effectively deleting it). Type the text you want to remove in the Find field and leave the Replace With field empty to delete that text from every selected filename.
Finder performs case insensitive matching by default, so searching for "draft" matches "Draft", "DRAFT", and "draft" in filenames. The replacement preserves the original casing of the surrounding text. Finder replaces every occurrence of the search string in each filename, so be careful with short strings that might appear in unexpected positions. Preview the results in the rename dialog before clicking Rename.
How Do You Find and Replace in Filenames with Terminal?
for loop with shell parameter expansion. The command for f in *; do mv "$f" "${f//oldtext/newtext}"; donereplaces every occurrence of "oldtext" with "newtext" in every filename. The double slash performs global replacement.Shell parameter expansion provides a built in find and replace mechanism without requiring external tools. The syntax ${variable//pattern/replacement}replaces all occurrences of the pattern in the variable's value. A single slash replaces only the first occurrence. This approach handles most plain text substitution tasks efficiently and works on any macOS system without additional installations.
For regex powered find and replace, Terminal uses sed or the Perl rename command. The sed approach pipes each filename through the regex engine: for f in *; do mv "$f" "$(echo "$f" | sed 's/old/new/g')"; done. Terminal provides no preview, so always test with echo first. For regex recipes and advanced patterns, see the regex rename guide and the remove spaces guide.
How Does Batchio Handle Find and Replace?
Batchio's plain text mode performs exact string matching with an optional case sensitivity toggle. This mode is ideal for simple substitutions where the search string is always identical across filenames. Replace "draft" with "final", remove "copy" from duplicate filenames, or swap project codes. The live preview updates as you type, showing the original and new filename for every loaded file.
Toggle the regex switch when plain text matching is not sufficient. Regex mode accepts any regular expression pattern in the Find field and supports capture group references in the Replace field. This single toggle transforms the Find & Replace rule from a simple text substitution tool into a full regex engine. Stack multiple Find & Replace rules for multi step operations. The batch rename guide covers the complete Batchio workflow.
When Should You Use Regex Instead of Plain Text?
Most find and replace operations are simple enough for plain text mode. Replacing a project name, removing a client prefix, or changing a word across filenames involves identical search strings. Plain text mode is faster to set up, easier to understand, and less error prone. It should be your default choice unless the task specifically requires pattern matching.
Regex becomes necessary when filenames contain variable content that follows a pattern. Removing numbers of varying length (1, 23, 456) requires \d+ because no single static string matches all variants. Extracting dates, reordering name components, and matching optional characters all require regex. If you find yourself running the same plain text replacement multiple times with different search strings, regex can usually accomplish the entire task in one pass. For regex patterns, see the regex cookbook.
What Are Common Find and Replace Scenarios?
Replacing spaces with underscores is one of the most frequent operations for web developers and anyone sharing files across operating systems. Spaces in filenames cause issues with URLs, command line tools, and some build systems. A simple find " " replace "_" operation solves this across an entire directory. The reverse operation (underscores to spaces) is equally common when preparing files for display.
Removing camera prefixes cleans up photo collections. Camera manufacturers use prefixes like IMG_, DSC_, DSCN_, P, and various other codes. A plain text find and replace removes these prefixes from every photo filename. Combine this with a numbering rule or date insertion rule to create meaningful filenames that replace the generic camera codes. For related cleanup operations, explore the prefix guide for removing camera prefixes from photo collections.
Frequently Asked Questions
Can Finder find and replace text in filenames?
Is find and replace in filenames case sensitive?
Can you find and replace in filenames without changing extensions?
How do you undo a find and replace rename on Mac?
Find and Replace with Live Preview
Download Batchio free on the Mac App Store. All 9 rule types included. Pro upgrade $4.99.
Coming Soon to the Mac App StoreMarcel Iseli is an indie app developer and the creator of Batchio. He builds native macOS utilities focused on productivity and file management, with a focus on lightweight, subscription-free tools.