How to check if file has a BOM in utf-8 text

file will tell you if there is a BOM. You can test:

$ /usr/bin/printf "\ufeff...\n" | file -
/dev/stdin: UTF-8 Unicode (with BOM) text

Note: according to the file changelog, this feature existed already in 2007. So, this should work on any current machine.


If you execute stat fileName it should give you exact the three characters. When I opened the file in the editor, I was unable to see anything. So noticing that the file size was 3 gave me clarity that it has a BOM.

Also, the post here was helful in my case.

hexdump -n 3 -C 2.txt
00000000 ef bb bf
ef bb bf // YES

Tags:

Unicode