Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Error when using 'sed' with 'find' command on OS X: "invalid command code ."

Error when using sed with find command on OS X: invalid command code.

Quick Answer: The issue is due to the period in the file path being interpreted as a special character by the `sed` command. Use double quotes around the file path to escape it, like this: `find ./ -type f -exec sed -i "s/192.168.20.1/new.domain.com/" {} \;`

The issue you're encountering occurs because the dot (.) in the file path is treated as a special character by the `find` command. When using `sed` with `find`, it's essential to escape any special characters in the file path to avoid this error.

💡 Why You Are Getting This Error

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Escaping the Dot

  1. Step 1: Replace the dot (.) in the file path with a backslash (\.). For example, replace `./file/path` with `./file\path

Method 2: Using Absolute Path

  1. Step 1: Use an absolute path instead of a relative one. For example, replace `./` with `/

🎯 Final Words

By applying these fixes, you should be able to successfully use the `sed` command with `find` on OS X. Remember to always escape special characters in file paths when using these commands.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions