Generally speaking, the file is divided into two major categories of text and binary files, text file editing is easy, Windows Notepad, UltraEdit are very useful, binary file editing under Windows also has a lot of tools, UltraEdit is good, but Linux? Today finally found a good way, but the final source can not find.
First create a binary file:
[Email protected] tmp]$ echo-n "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz" > Test.bin
[email protected] tmp]$ cat Test.bin
ABCDEFGHIJKLMNOPQRSTUVWXYZ Abcdefghijklmnopqrstuvwxyz[[email protected] tmp]$
Note that echo must keep up with the-n option, otherwise it will be automatically added with a newline line and then opened with Vim Test.bin
[Email protected] tmp]$ Vim-b Test.bin
Vim's-B option is to tell vim to open a binary file, which, if not specified, is appended with 0x0a, a newline character.
In command mode, type:
:%!xxd
If Vim is not followed by the-B option, The Hateful 0x0a will appear:
This is not the case if the-B option is available:
Then go to edit mode change, I will change a, b corresponding 41, 42 to 61, 62, A, b corresponding 61, 62 to 41, 42.
Back to command mode input:
:%!xxd-r
At this point we can find the position of AB and AB are interchangeable.
Finally, enter in command mode: Wq save to exit.
Use VIM with Xxd to view and edit binary files under Linux