How to Edit a Hex File in Linux From the Command Line


In the Linux operating system, many files contain data not stored in text mode. Examples include executable files with machine code, and data stored in binary formats understandable only to the programs intended to manipulate those files. You can edit files of that kind by using a binary editor that presents file contents as uninterpreted hexadecimal numbers. Linux has a built-in utility to edit hex files from the command line.

  • Log into the Linux computer in text mode. Linux will start a command shell, which will in turn prompt you to enter a text-mode command.

  • Invoke the "vim" text editor in binary mode as follows:

    vim -b

    Press "Enter."

  • Configure vim to operate in hex mode, then load the file you need to edit by typing the commands below:

    :setlocal wrap display=uhex

    :r !xxd myFile.hex

    Replace "myFile.hex" by the name of the file you need to edit. Press "Enter" after each line. Vim will display the contents of the file in both hex and text -- at the right end of each line -- modes.

  • Alter the contents of the file as needed by using the arrow keys to move around.

  • Exit vim while saving your modifications, by pressing "Esc" and then typing:


    Press "Enter."


Promoted By Zergnet


Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!