为了调试的目的,我需要递归地搜索一个目录中以 UTF-8字节顺序标记(BOM)开头的所有文件。我目前的解决方案是一个简单的 shell 脚本:
find -type f |
while read file
do
if [ "`head -c 3 -- "$file"`" == $'\xef\xbb\xbf' ]
then
echo "found BOM in: $file"
fi
done
或者,如果你更喜欢简短、不可读的俏皮话:
find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'\xef\xbb\xbf' ] && echo "found BOM in: $file";done
It doesn't work with filenames that contain a line break, but such files are not to be expected anyway.
Is there any shorter or more elegant solution?
Are there any interesting text editors or macros for text editors?