Elegant way to search for UTF-8 files with BOM?

What about this one simple command which not just finds but clears the nasty BOM? 🙂

find . -type f -exec sed '1s/^\xEF\xBB\xBF//' -i {} \;

I love “find” 🙂

Warning The above will modify binary files which contain those three characters.

If you want just to show BOM files, use this one:

grep -rl $'\xEF\xBB\xBF' .

Leave a Comment