How to Use the hexdump-"" hexadecimal Viewer

Source: Internet
Author: User

Description

The hexdump command is generally used to view the hexadecimal encoding of the "binary" file, but in fact it is used for more than that. The statement on the manual page is "ASCII, decimal, hexadecimal, octal dump", this is why the title of this article is "16", and it can view any file, not just binary files. In addition, xxd and OD can also do similar things, but I have never used them. When a program outputs a binary file, hexdump is often used to check whether the output is correct. Of course, you can also use tools such as ultraedit32 on Windows to view the file's hexadecimal encoding. But there are ready-made tools on Linux, so why not use them.

Common Parameters

If you want to see an ideal result, use the-C parameter to display the result in three columns (File offset, hexadecimal byte, and ASCII character ).

Format: hexdump-C binfile

Generally, the files are not too small. It is best to use less.

Format: hexdump-C binfile | less

 

Use Example 1 to compare the output results of various parameters

[Root @ new55 ~] # Echo/etc/passwd | hexdump
0000000 652f 6374 702f 7361 7773 0a64
000000c
[Root @ new55 ~] # Echo/etc/passwd | OD-x
0000000 652f 6374 702f 7361 7773 0a64
0000014
[Root @ new55 ~] # Echo/etc/passwd | xxd
0000000: 2f65 7463 2f70 6173 7377 640a/etc/passwd.
[Root @ new55 ~] # Echo/etc/passwd | hexdump-C <= standard hexadecimal and ASCII code Display (canonical hex + ASCII display)
00000000 2f 65 74 63 2f 70 61 73 73 77 64 0a |/etc/passwd. |
0000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-B <= single-byte octal display (one-byte octal display)
0000000 057 145 164 143 057 160 141 163 163 167 012
000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-C <= single-byte character display (one-Byte Character Display)
0000000/e t C/p a s w d \ n
000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-D <= double-byte decimal display (two-byte decimal display)
0000000 25903 25460 28719 29537 30579 02660
000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-O <= double-byte octal display (two-byte octal display)
0000000 062457 061564 070057 071541 073563 005144
000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-x <= dual-byte hexadecimal display (two-byte hexadecimal display)
0000000 652f 6374 702f 7361 7773 0a64
000000c
[Root @ new55 ~] # Echo/etc/passwd | hexdump-V
0000000 652f 6374 702f 7361 7773 0a64
000000c

 

Compare to compare, or the hexdump-C display is better.

Example 2 confirm the text file format

The line ending mark of text files on different operating systems is different, and the resulting problems are often encountered. For example, many Linux commands cannot properly process text files in DOS format. Windows/DOS text files end with \ r \ n as the line, while Linux/UNIX text files end with \ n as the line.

 

[Root @ new55 ~] # Cat test. BC
123*321
123/321
Size = 4; 123/321

[Root @ new55 ~] # Hexdump-C test. BC
00000000 31 32 33 2a 33 32 31 0a 31 32 33 2f 33 32 31 0a | 123*321.123/321. |
00000010 73 63 61 6C 65 3D 34 3B 31 32 33 2f 33 32 31 0a | scale = 4; 123/321. |
00000020 0a |. |
00000021
[Root @ new55 ~] #

 

Note: hexadecimal representation of common ASCII characters

\ R 0d

\ N 0a

\ T 09

DOS/Windows line break \ r \ n represents 0d 0a in hexadecimal notation

Linux/Unix line break \ n stands for the hexadecimal representation of 0a

 

Example 3 view WAV Files

Some IVR systems require 8 k Hz 8-bit audio files. You can use hexdump to check the specific Byte encoding.

[Root @ web186 root] # ls-l tmp.wav
-RW-r -- 1 Root 32381 2010-04-19 tmp.wav
[Root @ web186 root] # file tmp.wav
Tmp.wav: Riff (little-Endian) data, wave audio, ITU g.711 A-Law, Mono 8000Hz

[Root @ web186 root] # hexdump-C tmp.wav | less
00000000 52 49 46 46 75 7E 00 00 57 41 56 45 66 6D 74 20 | riffu ~.. Wavefmt |
00000000 52 49 46 46 75 7E 00 00 57 41 56 45 66 6D 74 20 | riffu ~.. Wavefmt |
00000010 12 00 00 00 06 00 01 00 40 1f 00 00 40 1f 00 | ...... @ ...... |
00000020 01 00 08 00 00 00 66 61 63 74 04 00 00 00 43 7E | ...... fact ...... C ~ |
00000030 00 00 64 61 74 61 43 7E 00 D5 D5 D5 D5 D5 |... DATAC ~........ |
00000040 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 | ...... |
*
201700a0 D5 D5 D5 D5 D5 D5 D5 D5 D5 55 D5 55 D5 D5 55 D5 | ...... U. |
201700b0 55 D5 D5 55 D5 55 D5 D5 55 D5 55 55 55 55 55 | u... U. uuuuuuu |
201700c0 55 55 55 55 55 55 D5 D5 D5 D5 D5 D5 D5 D5 | uuuuuuuu ...... |
201700d0 D5 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 |. uuuuuuuuuuuuuuuuu |
201700e0 55 55 55 55 55 55 55 D5 D5 D5 D5 D5 D5 | uuuuuuuuuu ...... |
201700f0 D5 D5 D5 55 55 55 55 55 55 55 55 55 55 55 55 55 |... uuuuuuuuuuuuuu |
00000100 55 55 55 55 55 55 55 55 55 55 55 D5 D5 D5 | uuuuuuuuuuuuu ...... |
00000110 D5 D5 D5 D5 D5 55 55 55 55 55 55 55 55 55 55 | ...... uuuuuuuuuu |
00000120 55 55 55 55 55 55 55 55 55 55 55 55 55 D5 | uuuuuuuuuuuuuuuuu .. |
00000130 D5 D5 D5 D5 D5 D5 D5 D5 55 55 55 55 55 55 | ...... uuuuuuu |
00000140 55 55 D5 55 55 55 55 55 55 55 55 55 55 55 55 | UU. uuuuuuuuuuuuu |
00000150 55 D5 D5 D5 D5 D5 D5 D5 D5 D5 55 55 55 55 55 | u ...... uuuuu |
00000160 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 | uuuuuuuuuuuuuuuuuuuu |
00000170 55 55 55 D5 D5 D5 D5 D5 D5 D5 D5 55 D5 55 | UUUU ...... u |
00000180 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 | uuuuuuuuuuuuuuuuuuuu |
00000190 55 55 55 55 55 55 D5 D5 D5 D5 D5 D5 55 | uuuuuuuu ...... u |
000001a0 55 55 55 55 55 55 55 D5 55 55 55 55 55 55 55 | uuuuuuuu... uuuuuuuuu |
000001b0 55 55 55 55 55 55 D5 55 D5 55 55 55 55 55 55 | uuuuuuuu. uu. uuuuu |
000001c0 55 55 D5 55 D5 D5 55 D5 55 55 55 55 55 55 55 | UU. U... U. uuuuuuuuu |
000001d0 55 55 55 55 55 55 55 55 55 55 55 55 55 D5 | uuuuuuuuuuuuuuuuu. |
000001e0 55 D5 D5 D5 55 55 55 55 55 55 55 55 55 55 55 | u... uuuuuuuuuuuu |
000001f0 55 55 55 55 55 55 55 55 55 55 D5 55 55 D5 | uuuuuuuuuuuu. uu. |
00000200 55 55 55 55 55 55 55 55 D5 D5 D5 D5 55 55 | uuuuuuuuuu ...... UU |
00000210 55 55 55 55 55 55 55 55 55 55 55 55 55 D5 | uuuuuuuuuuuuuuuuuuuu. |
00000220 55 55 D5 55 D5 55 55 D5 55 D5 55 55 D5 55 D5 D5 | UU. U. uu. u .. |
00000230 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 | ...... |
*
00000ba0 D5 D5 D5 D5 D5 D5 D5 D5 D5 D5 55 D5 55 D5 55 D5 | ...... U. |
00000bb0 55 D5 55 D5 55 D5 55 D5 55 D5 55 55 55 55 55 | UU. U... U. uuuuuuu |
00000bc0 55 55 55 55 55 55 55 55 D5 D5 55 55 55 55 55 | uuuuuuuuu... uuuuuu |
00000bd0 55 55 55 55 55 55 D5 55 55 55 55 55 D5 55 | uuuuuuuu. uuuuuu. u |
00000be0 55 55 55 55 55 55 55 55 55 D5 55 55 55 55 | uuuuuuuuuuu. uuuuu |
00000bf0 55 55 55 55 55 55 55 55 D5 D5 55 55 55 55 D5 | uuuuuuuuu... uuuuuu. |
00000c00 D5 55 55 55 D5 D5 D5 55 55 55 55 D5 D5 55 |. UUUU... u |
: Q

[Root @ web186 root] #

Reprinted from: http://codingstandards.iteye.com/blog/805778

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.