3

Disclaimer: This is not the same as What are some good GUI binary viewers/editors?.

How do I edit the binary data of a file in a gedit like editor? Eg:

00001010101010010101

And how do I edit the hexadecimal data of a file in a gedit like editor? eg:

91021AF9B

I do not want one editor with both. I want two different editors.

I have looked a GHex and it is not what I want.

fosslinux
  • 3,831
  • Look into Bless hex editor (for GNOME) or ncurses-hexedit, hexer, or hexcurse (for console) – Nick Weinberg Jun 14 '16 at 00:52
  • Thanks Nick. Bless looks good, but from what I can make out, hexedit is only for Windows? – fosslinux Jun 14 '16 at 00:54
  • 1
    bless, hexedit, ncurses-hexedit, hexer, and hexcurse are the names of packages available in the Ubuntu software repositories. To install any of them, open a terminal window (alt--ctrl-T) and type sudo apt install bless (replacing bless with the name of your desired program) – Nick Weinberg Jun 14 '16 at 00:58
  • wxhexeditor might be another option with a GUI interface – Nick Weinberg Jun 14 '16 at 00:59
  • Wow there is a lot of hex editors. What about binary? – fosslinux Jun 14 '16 at 01:06
  • 2
    You know, you could always use vim for pretty much everything http://vim.wikia.com/wiki/Improved_hex_editing and http://usevim.com/2012/06/20/vim-binary-files/ and finally http://vi.stackexchange.com/questions/343/how-to-edit-binary-files-with-vim – mchid Jun 14 '16 at 01:59
  • Thanks you guys. Could someone formulate these into a answer? – fosslinux Jun 14 '16 at 02:23

1 Answers1

8

You can use vim which should already be installed.

Just to make sure, go ahead and install vim:

sudo apt-get update
sudo apt-get install vim

Now, use the vim command :%! xxd -b to edit binary like in this example:

vim /path/to/filename

note: you can drag and drop the file into the terminal to automatically fill in the path for you

FYI, the :%! command prefix allows you to pipe the current file's contents to command's stdin, and replaces the file's contents with command's stdout. xxd is a linux command.

Once the file is open, press ESC and then type :%! xxd -b and then press ENTER.

Alternatively, you can add the flag -g4 to group the bits into 32 bit packets like :%! xxd -b -g4

enter image description here

For hex edit, use the vim command :%! xxd instead or :%! xxd -g4

d

Press ESC and then i for "INSERT" mode which allows you to edit.

Press ESC and then type :w followed by ENTER to save the file.

Press ESC and then type :q followed by ENTER or ESC and then type :q! followed by ENTER to exit the file.

Vim takes some getting used to but is really great once you take the time to learn how it works.

Additionally, vim allows you to edit just about anything including sqlite and all kinds of other stuff.

Also, when you convert a binary to hex and then edit, I think you may need to convert back to binary by using :%! xxd -r command as described here.

More info can be found at the official wiki by clicking here.

Here is a similar post:

https://unix.stackexchange.com/questions/282215/how-to-view-a-binary-file/282220

Click here for more info on editing your .vimrc file to allow some related commands.


A very similar editor is bvi. Run the following command to install:

sudo apt-get install bvi

Click here for more info.

mchid
  • 43,546
  • 8
  • 97
  • 150