Please recommend a hex editor for shell

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.


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.


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