Linux Command learning Summary: hexdump,

Source: Internet
Author: User

Linux Command learning Summary: hexdump,

Command introduction:

Hexdump is a binary file viewing tool in Linux. It can convert binary files into ASCII, octal, decimal, and hexadecimal formats for viewing.

Command path:/usr/bin/hexdump

Command syntax:

Hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file...]

Command parameters:

This command parameter is the hexdump command parameter under Red Hat Enterprise Linux Server release 5.7. The hexdump command parameters may be different for different versions of Linux.

Parameters

Long Parameter

Description

-B

 

Each byte is displayed in octal format. A row contains 16 bytes and the offset value is displayed in hexadecimal format.

-C

 

Each byte is displayed as ASCII characters

-C

 

Each byte is displayed as hexadecimal and corresponding ASCII characters.

-D

 

Two bytes are displayed in decimal format.

-E

 

Format output

-F

 

Specify a file that contains one or more newline separated format strings. Empty lines and lines whose first non-blank character is a hash mark (#) are ignored.

-N

 

Only the first n characters in length

-O

 

Two bytes are displayed in octal format.

-S

 

Output from offset

-V

 

The-v option causes hexdump to display all input data. Without the-v option, any number of groups of output lines, which wocould be identical to the immediately preceding group of output lines

-X

 

Dual-byte hexadecimal display

Example:

1: view the help information of the hexdmp command

[root@DB-Server ~]# man hexdump

2: display the characters in the file in octal format.

[root@DB-Server ~]# cat >test.txt
ABCDEF    
GHIJKM
123456
[root@DB-Server ~]#  hexdump -b test.txt
0000000 101 102 103 104 105 106 012 107 110 111 112 113 115 012 061 062
0000010 063 064 065 066 012                                            
0000015

Note: A row contains 16 bytes, And the offset value is displayed in hexadecimal notation (as shown below, the first line of the string is only displayed in D, 16th bytes, f12 * DFDF line feed display)

[root@DB-Server ~]# cat >test.txt
ABCDEFGHIJKLMNODF12*DFDF
 
[2]+  Stopped                 cat > test.txt
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# hexdump -b test.txt 
0000000 101 102 103 104 105 106 107 110 111 112 113 114 115 116 117 104
0000010 106 061 062 052 104 106 104 106 012                            
0000019
[root@DB-Server ~]# hexdump -c test.txt 
0000000   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   D
0000010   F   1   2   *   D   F   D   F  \n                            
0000019

3: display characters in files with ASCII characters

[root@DB-Server ~]# hexdump -c test.txt 
0000000   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   D
0000010   F   1   2   *   D   F   D   F  \n                            
0000019
 

When hexdump is displayed with ASCII characters, you can output line breaks. This function can be used to check whether the file is a Linux line break or a Widows line break. As shown below

4: display characters in the file in hexadecimal notation and corresponding ASCII characters

[root@DB-Server ~]# hexdump -C test.txt 
00000000  41 42 43 44 45 46 47 48  49 4a 4b 4c 4d 4e 4f 44  |ABCDEFGHIJKLMNOD|
00000010  46 31 32 2a 44 46 44 46  0a                       |F12*DFDF.|
00000019

5: only the first n characters in the format file

[root@DB-Server ~]# hexdump -C -n 5 test.txt 
00000000  41 42 43 44 45                                    |ABCDE|
00000005

6: Output in offset format. The-s 5 parameter is specified as follows. The preceding ABCDE character is missing.

 
[root@DB-Server ~]# hexdump -C test.txt 
00000000  41 42 43 44 45 46 47 48  49 4a 4b 4c 4d 4e 4f 44  |ABCDEFGHIJKLMNOD|
00000010  46 31 32 2a 44 46 44 46  0a                       |F12*DFDF.|
00000019
[root@DB-Server ~]# hexdump -C -s 5 test.txt 
00000005  46 47 48 49 4a 4b 4c 4d  4e 4f 44 46 31 32 2a 44  |FGHIJKLMNODF12*D|
00000015  46 44 46 0a                                       |FDF.|
00000019

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.