118

Can you recommend a hex editor that can be run from shell? I need to be able to edit not only view the content.

belacqua
  • 23,540
Aviran
  • 1,331

11 Answers11

140
xxd

This tool is the most commonly available I have found for this type of task (available by default on both latest Ubuntu and macOS). You can remove the ascii readable part on the right if needed using -p and you can revert (change ascii input to binary data) using the -r function. Here are some simple example uses:

Converting to hex with ascii view:

echo example | xxd

Converting to a hexdump (no ascii view on the right):

echo example | xxd -p

Converting from a hexdump back to binary data:

echo 746573740a | xxd -p -r

You can get much more complex with this in shell scripts. I have actually used this and "dd" to scan for specific sequences and modify them in a predefined fashion all from a shell script using nothing but bash, dd, and xxd. You actually don't need dd for this either as you can "seek" to a specific location and write to that location the byte sequence you need. The biggest advantage to this approach is its easily scriptable.

Goblinlord
  • 1,743
  • 2
  • 11
  • 8
47

There is also DHEX

apt-cache show dhex

ncurses based hex editor with diff mode

This is more than just another hex editor: It includes a diff mode, which can be used to easily and conveniently compare two binary files. Since it is based on ncurses and is themeable, it can run on any number of systems and scenarios. With its utilization of search logs, it is possible to track changes in different iterations of files easily.

If you are not familiar with vim or emacs, this one doesn't seem to have much of a learning curve.

mivk
  • 5,811
42

You might be able to use vi/vim as a hex editor too (it can call xxd).

Enter hex mode:

:%!xxd

Exit hex mode:

:%!xxd -r

Source: Using vi as a hex editor

friederbluemle
  • 462
  • 7
  • 11
klcant
  • 579
25

emacs has a hexl-mode for hex editing.

psusi
  • 38,031
14

This one is dead simple to use:

sudo apt-get install hexcurse
11

I know this is an old question, but I was dissatisfied with all of the answers here. I was looking for a hex editor that allowed for me to create my own binary files (aka insert mode) and could handle very large files.

I came across tweak, which fulfills both of these requirements, as well as the OPs.

  • Tweak supports insert mode (not particularly useful if you're editing an executable file or a filesystem image, but can be extremely handy in other file formats such as PNG).
  • Cutting, copying and pasting within the file you are editing is extremely efficient. No matter how big the chunk of data you are moving around - even if it's a 200Mb section of a CD image - Tweak will always perform the operation effectively instantly.
  • Tweak supports lazy loading of the input file: rather than sucking it all into memory straight away, it simply remembers which parts of the editing buffer are copies of which parts of the input file and refers to the file on disk when it needs to. Tweak only has to take significant time when you genuinely need it to read the entire file. The only two operations with this property are searching, and saving the modified version of the file to disk. Everything else is instant.
Gogeta70
  • 477
  • 5
  • 11
4

Bless Hex Editor is a is a binary (hex) editor and 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.

You can dounload it from here: http://packages.debian.org/sid/all/bless/download.

To install it, see How do I install a .deb file via the command line?

Need more?

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
3

Try hexed, it's made for use in scripts and make files.

b.zaar
  • 31
  • 1
2

There is also ht. Install it as

sudo apt-get install ht

and then run it by typing hte.

I haven't tried it with really large files/partitions, though.

fjflores
  • 121
1

You might as well use the good old Midnight Commander: mc.

To install:

sudo apt-get update
sudo apt-get install mc

The mc command gives you an ncurses like file explorer. It makes heavy use of the function buttons in the top row of the keyboard (F1 - F10). A line at the bottom of the console indicates the function assigned to a specific function key. To save screen space the F is omitted, so 3View means press F3 to view the file.

Warning:
F4 just fires up your default editor. Use F3to view the file and then switch into HEX mode with F4.

Here's a rough list of key presses:

  • Use cursor keys to move to the file in question
  • Press F3 - View to look at the file (Do NOT press F4 - Edit)
  • Press F4 - Hex to switch into hex editing mode
  • Use the cursor keys to move around in the file
  • Press TAB to toggle the edit cursor between the HEX and ASCII column
  • Edit to your liking
  • Press F7 - HxSrch to search in the file (HEX or ASCII)
  • Press F6 - Save to save your work
  • Press F10 - Quit to quit the hex editor
  • Press F10 - Quit again to quit the Midnight Commander

The mouse might work as well, just try to click on the function button line at the bottom of the screen.

To verify the work I usually dump the file before and after editing and diff the dump:

xxd hexfile > before
# edit with mc
mc
xxd hexfile > after
diff before after

Instead of xxd the cli tool hd works as well. hdmight already be installed on your system.

0

I have written hextazy an hexadecimal editor with colors written in rust.

It has the following features:

  • colored output, based on the byte value.
  • search, for both hex values and ascii strings.
  • undo and redo (Ctrl+Z, Ctrl+Y).
  • insert mode (Ctrl+J)
  • delete byte (Del key, only in insert mode)
  • jump to an address with the command :0xaddress.

You can find pre-compiled binaries on the release page.

The project is developed on Github here: https://github.com/0xfalafel/hextazy

Hextazy hex editor