How to edit a binary file on Unix systems

Viewed 170174

On Windows machines there are lots of third-party editors available to edit a binary file.

How can I edit a binary file on a Unix system?

12 Answers

In Vim, you can type :%!xxd to turn it into a hex editor. :%!xxd -r to go back to normal mode. xxd is shipped in a Vim installation.

See here for some remarks about editing binary files with Vim (it boils down to :set binary to avoid trouble. Use only the "R" or "r" command to change text, and don't delete characters).

If you are an Emacs fan, see here for a guide on how to edit a binary file with Emacs.

You can also try GHex 2 GNOME utilities. This give you the automated hex-to-ASCII on the side, as well as the various character/integer decodes at the bottom.

ghex2

(Source: googlepages.com)

There are many more hex editors on Linux/Unix....

I use hexedit on Ubuntu:

sudo apt-get install hexedit

Bless is a high quality, full featured hex editor.

It is written in mono/Gtk# and its primary platform is GNU/Linux. However it should be able to run without problems on every platform that mono and Gtk# run. Main Features Bless currently provides the following features:

  • Efficient editing of large data files and block devices.
  • Multilevel undo - redo operations.
  • Customizable data views.
  • Fast data rendering on screen.
  • Multiple tabs.
  • Fast find and replace operations.
  • A data conversion table.
  • Advanced copy/paste capabilities.
  • Highlighting of selection pattern matches in the file.
  • Plugin based architecture.
  • Export of data to text and html (others with plugins).
  • Bitwise operations on data.
  • A comprehensive user manual.

copied from http://home.gna.org/bless/

I like KHexEdit, which is part of KDE.

Its "Windows style" UI is probably quite quick to learn for most people (compared to Vim or Emacs anyway).

There's a lightweight binary editor called hexedit.

I tried using it for editing ELF binaries in Linux at least.

For small changes, I have used hexedit.

It is simple, but fast and useful.

Related