Use Vim with xxd in Linux to view and edit binary files

Source: Internet
Author: User
Tags ultraedit

Generally, files are divided into two categories: text files and binary files. It is easy to edit text files. notepad and ultraedit in windows are easy to use. There are also many tools for editing binary files in windows, ultraedit is also good, but what about Linux? Today, I finally found a good method, but the final source cannot be found.

 

First, create a binary file:

 
[Oracle @ logserver TMP] $ echo-n "abcdefghijklmnopqrstuvwxyz"> test. Bin [Oracle @ logserver TMP] $ CAT test. Bin zookeeper [Oracle @ logserver TMP] $

Note that ECHO must keep up with the-n option; otherwise, a line feed will be automatically added and test. Bin will be opened with vim.

 
[Oracle @ logserver TMP] $ vim-B test. Bin

The-B Option of VIM tells Vim to open a binary file. If this parameter is not specified, 0x0a is added to the end, which is a line break.

In command mode, type:

 
: %! Xxd

If the-B option is not added to VIM, the hateful 0x0a will appear:

If option-B is available, this is not the case:

Then, change the edit mode. I will change the 41 and 42 values corresponding to a and B to 61 and 62, and change the 61 and 62 values corresponding to a and B to 41 and 42.

Return to the command mode and enter:

 
: %! Xxd-R

Now we can find that the positions of AB and AB are changed.

Finally, enter WQ in command mode to save and exit.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.