I used the Linux command hexdump-"16" binary viewer (reprint)

Source: Internet
Author: User

Reprint: http://codingstandards.iteye.com/blog/805778

This article link: http://codingstandards.iteye.com/blog/805778 (reproduced please specify the source)

Description of Use

The Hexdump command is typically used to look at the hexadecimal encoding of a binary file, but in fact it does more than that, and the manual page says "ASCII, decimal, hexadecimal, octal dump", which is why the title of this article is "16" To the cause, and it can view any file, not just the binary file. There are also xxd and OD can do similar things, but I have never used. In the program output binary format files, common hexdump to check the output is correct. Of course, you can also use tools like UltraEdit32 on Windows to view the hexadecimal encoding of files, but there are tools available on Linux, so why not use them?

Common parameters

If you want to see better results, using the-c parameter, the display results are divided into three columns (file offset, byte 16, ASCII characters).

Format: Hexdump-c binfile

General documents are not too small, preferably with less to match.

Format: hexdump-c binfile | Less

Use example example one to compare the output of various parameters

[Email protected] ~]#echo/etc/passwd | Hexdump
0000000 652f 6374 702f 7361 7773 0a64
000000c
[Email protected] ~]#echo/etc/passwd | Od-x
0000000 652f 6374 702f 7361 7773 0a64
0000014
[Email protected] ~]#echo/etc/passwd | Xxd
0000000:2f65 7463 2f70 6173 7377 640a/etc/passwd.
[Email protected] ~]#echo/etc/passwd | Hexdump-c16 binary and ASCII code display for <== specification (Canonical HEX+ASCII displays)
00000000 2f (2f), 0a |/etc/passwd.|
0000000c
[Email protected] ~]#echo/etc/passwd | Hexdump-b<== single-byte octal displays (One-byte octal display)
0000000 057 145 164 143 057 160 141 163 163 167 144 012
000000c
[Email protected] ~]#echo/etc/passwd | Hexdump-c<== single-byte character display (One-byte character displays)
0000000/e T c/p a s S W d \ n
000000c
[Email protected] ~]#echo/etc/passwd | Hexdump-d<== double-byte decimal display (two-byte decimal displays)
0000000 25903 25460 28719 29537 30579 02660
000000c
[Email protected] ~]#echo/etc/passwd | Hexdump-o<== double-byte octal display (two-byte octal displays)
0000000 062457 061564 070057 071541 073563 005144
000000c
[[email protected] ~]# echo/etc/passwd | hexdump-x <== Double-byte hexadecimal display (Two-byte hexadecimal display)
0000000 652f 6374 702f 7361 7773 0a64
000000c
[Email protected] ~]# echo/etc/passwd | hexdump-v
0000000 652f 6374 702f 7361 7773 0a64
000000c

Compare to compare, or hexdump-c display effect is better.

Example two confirming the format of a text file

text files on different operating systems on the end of the line flag is not the same, often encounter the problem caused. For example, many Linux commands do not work well with DOS-formatted text files. The text file under Windows/dos ends with \ r \ n as the line, and the text file under Linux/unix ends with \ n as the line.

[Email protected] ~]# cat TEST.BC
123*321
123/321
scale=4;123/321

[Email protected] ~]# hexdump-c TEST.BC
00000000 2a, 0a, 2f, 0a, |123*321.123/321.|
00000010, 6c 3d, 3b, 2f, 0a |scale=4;123/321.|
00000020 0a |.|
00000021
[Email protected] ~]#

Note: Hexadecimal representation of common ASCII characters

\ r 0D

\ n 0A

\ t 09

Dos/windows line break \ r \ n hexadecimal means 0D 0A

Linux/unix newline character \ n is hexadecimal representation of 0A

Example three viewing WAV files

Some IVR systems require 8K Hz 8-bit voice files, and you can use Hexdump to look at specific byte encodings.

[Email protected] root]# ls-l tmp.wav
-rw-r--r--1 root root 32381 2010-04-19 tmp.wav
[[email protected] root]# file tmp.wav
Tmp.wav:RIFF (Little-endian) data, WAVE Audio, ITU g.711 A-law, Mono 8000 Hz

[Email protected] root]#Hexdump-c Tmp.wav | Less
00000000-----7e, 6d 74 20 | riffu~. wavefmt |
00000000-----7e, 6d 74 20 | riffu~. wavefmt |
00000010, XX, 1f, 1f 00 00 | [Email protected]@...|
00000020-XX-XX-------7e |......fact .... c~|
00000030 (7e), D5 d5 d5 d5 d5 d5 | datac~........|
00000040 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 d5 |................|
*
000000a0 d5 d5 d5 d5 d5 d5 d5 d5 d5 "d5" d5 d5 | d5 | ... U.u. u.|
000000b0 d5 d5 d5, D5 d5, D5 55 55 55 55 55 55 | U.. U.u. u.uuuuuu|
000000c0 d5 d5 d5 d5 d5 d5 d5 d5 d5 | uuuuuuu.........|
000000d0 D5 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 |. uuuuuuuuuuuuuuu|
000000e0-d5 d5 d5 d5 d5 d5 d5 | uuuuuuuuu.......|
000000f0 d5 d5 d5 d5 55 55 55 55 55 55 55 55 55 55 55 55 | ... uuuuuuuuuuuu|
00000100-In-A-d5 d5 d5 d5 | uuuuuuuuuuuu....|
00000110 d5 d5 d5 d5 d5 d5 55 55 55 55 55 55 55 55 55 55 | ... uuuuuuuuuu|
00000120-In-A-d5-d5 | uuuuuuuuuuuuuu..|
00000130 d5 d5 d5 d5 d5 d5 d5 d5 d5 55 55 55 55 55 55 55 | ... uuuuuuu|
00000140 D5 55 55 55 55 55 55 55 55 55 55 55 55 55 | Uu. uuuuuuuuuuuuu|
00000150 d5 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 55 | uuuuuuuuuuuuuuuu|
00000170 d5 d5 d5 d5 d5 d5 d5 d5 d5-d5 55 | Uuuu ..... u.u|
00000180 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 | uuuuuuuuuuuuuuuu|
00000190 d5 d5 d5 d5 d5 d5 d5 d5 55 | Uuuuuuu ..... u|
000001a0 d5 d5 55 55 55 55 55 55 55 | Uuuuuuu. uuuuuuu|
000001b0-D5 D5 55 55 55 55 55 | Uuuuuuu. Uu. uuuuu|
000001c0 d5 d5 d5 d5 55 55 55 55 55 55 55 55 | Uu. U.. u.uuuuuuuu|
000001D0----------------d5 | uuuuuuuuuuuuuuu.|
000001e0 d5 d5 d5 d5 55 55 55 55 55 55 55 55 55 55 55 | U .... uuuuuuuuuuu|
000001F0-In-A-d5-d5 | Uuuuuuuuuuuu. uu.|
00000200-d5 d5 d5 d5 d5 55 55 | Uuuuuuuuu ..... uu|
00000210----------------d5 | uuuuuuuuuuuuuuu.|
00000220 d5-d5-d5-d5-d5-d5 d5 | Uu. U.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 d5-d5-d5 | ... Uu. u.|
00000bb0 d5 d5 d5 d5 55 55 55 55 55 55 | Uu. U.u. u.uuuuuu|
00000bc0-D5 D5 55 55 55 55 55 | Uuuuuuuuu. uuuuu|
00000bd0-d5-55-d5--- Uuuuuuu. Uuuuuu. u|
00000BE0-D5 55 55 55 55 (in) Uuuuuuuuuuu. uuuu|
00000bf0-d5 d5-----d5 | Uuuuuuuu. uuuuu.|
00000c00 d5, D5 d5 d5, d5 d5 55 |. Uuuu ... Uuuuu. u|
:Q

[Email protected] root]#

Problem thinking related information

"1" Kindle ' s blog hexdump,od,xxd

"2" Hangzhou Mei Chuang Science and Technology Resource Center use Hexdump to view a binary file

I used the Linux command hexdump-"16" binary viewer (reprint)

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.