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

unicode

How can I check if a utf-8 text file have a BOM from command line?

file command shows me UTF-8 Unicode text.

But I don't know it means there is no BOM in the file.

I'm using Ubuntu 12.04.

Best Answer

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.