Edit binary files in Linux


In this post I’ll mention how to edit binary files using vi and the utility xxd that is a part of vi.

vi in hex mode

Use the xxd command by typing :%!xxd. Edit hex data. Quit hex mode with :%!xxd -r.

Using xxd command

You can use the xxd command outside vi. If you have an existing binary file, you can convert it to hex

xxd -g 1 file.bin > file.hex

You can then edit the hex and convert it back to binary

xxd -r file.hex > file.bin

One nice little thing that xxd does is to produce a C static array definition, very convenient for embedding resource files

xxd -i file.bin

3 thoughts on “Edit binary files in Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s