Commands to Check, Add, and Remove UTF-8 BOM <U+FEFF> [Linux, macOS Edition]

Tadashi Shigeoka ·  Tue, March 26, 2019

I’ll introduce commands to remove UTF-8 BOM <U+FEFF> on Linux and macOS.

Linux

Checking for UTF-8 BOM

You can check for the presence of UTF-8 BOM using the file command.

$ file sample.txt
sample.txt: ASCII text # UTF8 without BOM
$ file sample.txt
sample.txt: UTF-8 Unicode (with BOM) text # UTF8 with BOM

Adding and Removing UTF-8 BOM

UTF-8 BOM can be added or removed using the nkf command.

$ nkf --overwrite --oc=UTF-8 sample.txt # Remove BOM
sample.txt: ASCII text
$ nkf --overwrite --oc=UTF-8-BOM sample.txt # Add BOM
sample.txt: UTF-8 Unicode (with BOM) text

That’s all from the Gemba on wanting to remove UTF-8 BOM <U+FEFF> from the Terminal on Linux and macOS.