<p>For debugging purposes, I need to recursively search a directory for all files which start with a UTF-8 byte order mark (BOM). My current solution is a simple shell script:</p>

<pre><code>find -type f |
while read file
do
    if [ "`head -c 3 -- "$file"`" == $'\xef\xbb\xbf' ]
    then
        echo "found BOM in: $file"
    fi
done</code></pre>

<p>Or, if you prefer short, unreadable one-liners:</p>

<pre><code>find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done</code></pre>

<p>It doesn't work with filenames that contain a line break,
but such files are not to be expected anyway.</p>

<p>Is there any shorter or more elegant solution?</p>

<p>Are there any interesting text editors or macros for text editors?</p>

If you accept some false positives (in case there are non-text files, or in the unlikely case there is a ZWNBSP in the middle of a file), you can use grep:
```
```
fgrep -rl `echo -ne '\xef\xbb\xbf'` .
```
```