Sometimes one needs to edit a binary file. The easiest way to do this is using a hex editor which displays all bytes in a file as hex.
The vi
editor has a handy feature that does just this:
- open the file using the
-b
option. This turns off any automatic formatting. For example:vi -b data
- convert the binary data into hex format by entering
:%!xxd
- do the required edits (move around using the cursor keys, start inserting characters with the
i
key, leave inserting with theESC
key, delete characters with thex
key) - convert the hex data back to binary by entering
:%!xxd -r
- write back your data by entering
:w
followed by:q
or leave without writing the data by entering:q!