To check binary file content xxd <file name>

To edit binary file

  • Open the binary file normally with vim vim <file name>
  • Convert them to xxd-human readable format :%!xxd
  • Edit the hex part in the left
  • Convert xxd-human readable format back to binary :%!xxd -r
  • Save modified content :w

Here are some useful vim commands to work with binary file

  • :as(scii) or ga: print asscii value of the character under cursor
  • g8: print the utf-8 encoded binary of the character being displayed under the cursor, regardless the value of fenc
  • 8g8: find the first invalid utf8 byte sequence.
  • To prevent vim from appending new line character a0 at the end of file :set binary, then :set noeol
  • To open file in binary format, without de-coding its content. In other words, utf-8 compatible characters are shown as human readable while illegal characters are shown as hex value

:set binary then :e (you must re-open the buffer)

or

vim -b <file name>

or

:e ++binary