Use the hexdump command

Source: Internet
Author: User

The hexdump command is a tool for printing hexadecimal data in Linux. It can output hexadecimal data in the specified format. It is particularly useful. It is out of order to use it with the EEPROM.

Today we will introduce the use of an hexdump command:


First, we prepare a test file for testing. The hexadecimal format is as follows:

[Plain]
View plaincopyprint?
  1. 00 01 02 03 04 05 06 07 08 09 0a 0b 0C 0d 0e 0f
  2. 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1f
  3. 20 21 22 23 24 25 26 28 29 2a 2B 2C 2D 2E 2f
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F

Option:


-N Length

Only format the first length of the input file



-C Outputs hexadecimal and corresponding characters

Input:

[Plain]
View plaincopyprint?
  1. Hexdump-N 13-C Test
hexdump -n 13 -C test

Output:

[Plain]
View plaincopyprint?
  1. 00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0C | .......... |
  2. 0000000d
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c           |.............|0000000d



-S: Output starting from offset

Input:

[Plain]
View plaincopyprint?
  1. Hexdump-N 13-C-S 30 test
 hexdump -n 13 -C -s 30 test

Output:

[Plain]
View plaincopyprint?
  1. 2017001e 1E 1f 20 21 22 23 24 25 26 27 28 29 2a | ..! "# $ % & '() * |
  2. 0000002b
0000001e  1e 1f 20 21 22 23 24 25  26 27 28 29 2a           |.. !"#$%&'()*|0000002b


Hexdump advanced usage:
-E specifies the format string, which is contained in a pair of single quotes. The format string is like: 'A/B "format1" "format2 "'
Each format string is composed of three parts, each separated by spaces. The first is a/B, and B indicates that format1 is applied to every B input bytes, a Indicates that format2 format is applied to each input byte of A. Generally, A> B is used, and B can only be 1, 2, and 4. In addition, a can be omitted, and a = 1 If omitted. You can use a string similar to printf in format1 and format2, for example: % 02d: two decimal places % 03x: three-digit hexadecimal % 02o: Two octal workers % C: Single CharacterAnd so on
There are some special usage: % _ Ad: Mark the sequence number of the next output byte, in decimal format % _ Ax: Number of the next output byte, expressed in hexadecimal notation
% _ AO: the serial number of the next output byte, expressed in octal.
% _ P: cannot be replaced. If you want to display multiple format strings in the same line, you can use multiple-e options

Example 1:Input:

[Plain]
View plaincopyprint?
  1. Hexdump-e '2014 "% 02x" "|" '-e '2014 "% _ p" "\ n" 'test
 hexdump -e '16/1 "%02X " "  |  "' -e '16/1 "%_p" "\n"' test

Output:

[Plain]
View plaincopyprint?
  1. 00 01 02 03 04 05 06 07 08 09 0a 0b 0C 0d 0e 0f | ................
  2. 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1f | ................
  3. 20 21 22 23 24 25 26 28 29 2a 2B 2C 2D 2E 2f |! "# $ % & '() * + ,-./
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F  |  ................10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F  |  ................20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F  |   !"#$%&'()*+,-./

Example 2:Input:

[Plain]
View plaincopyprint?
  1. Hexdump-e '1/1 "0x % 08_ax" '-e '8/1 "% 02x" * "'-e' 8/1" % _ p "" \ n "'test
hexdump -e '1/1 "0x%08_ax "' -e '8/1 "%02X " " *  "' -e '8/1 "%_p" "\n"' test
Output:

[Plain]
View plaincopyprint?
  1. 0x00000000 00 01 02 03 04 05 06 07 *........
  2. 0x00000008 08 09 0a 0b 0C 0d 0e 0f *........
  3. 0x00000010 10 11 12 13 14 15 16 17 *........
  4. 0x00000018 18 19 1A 1B 1C 1D 1E 1f *........
  5. 0x00000020 20 21 22 23 24 25 26 27 *! "# $ % &'
  6. 0x00000028 28 29 2a 2B 2C 2D 2E 2f * () * + ,-./
0x00000000 00 01 02 03 04 05 06 07 *  ........0x00000008 08 09 0A 0B 0C 0D 0E 0F *  ........0x00000010 10 11 12 13 14 15 16 17 *  ........0x00000018 18 19 1A 1B 1C 1D 1E 1F *  ........0x00000020 20 21 22 23 24 25 26 27 *   !"#$%&'0x00000028 28 29 2A 2B 2C 2D 2E 2F *  ()*+,-./

Example 3:Input:

[Plain]
View plaincopyprint?
  1. Hexdump-e '1/1 "% 02_ad #" '-E'/1 "hex = % 02x *"'-E'/1 "dec = % 03d |" '-e' /1 "Oct = % 03o" '-E'/1 "\ _ \ n"'-N 20 test
hexdump -e '1/1 "%02_ad#    "' -e '/1 "hex = %02X * "' -e '/1 "dec = %03d | "' -e '/1 "oct = %03o"' -e '/1 " \_\n"' -n 20 test
Output:

[Plain]
View plaincopyprint?
  1. 00 # hex = 00 * dec = 000 | Oct = 000 _
  2. 01 # hex = 01 * dec = 001 | Oct = 001 _
  3. 02 # hex = 02 * dec = 002 | Oct = 002 _
  4. 03 # hex = 03 * dec = 003 | Oct = 003 _
  5. 04 # hex = 04 * dec = 004 | Oct = 004 _
  6. 05 # hex = 05 * dec = 005 | Oct = 005 _
  7. 06 # hex = 06 * dec = 006 | Oct = 006 _
  8. 07 # hex = 07 * dec = 007 | Oct = 007 _
  9. 08 # hex = 08 * dec = 008 | Oct = 010 _
  10. 09 # hex = 09 * dec = 009 | Oct = 011 _
  11. 10 # hex = 0a * dec = 010 | Oct = 012 _
  12. 11 # hex = 0b * dec = 011 | Oct = 013 _
  13. 12 # hex = 0C * dec = 012 | Oct = 014 _
  14. 13 # hex = 0d * dec = 013 | Oct = 015 _
  15. 14 # hex = 0e * dec = 014 | Oct = 016 _
  16. 15 # hex = 0f * dec = 015 | Oct = 017 _
  17. 16 # hex = 10 * dec = 016 | Oct = 020 _
  18. 17 # hex = 11 * dec = 017 | Oct = 021 _
  19. 18 # hex = 12 * dec = 018 | Oct = 022 _
  20. 19 # hex = 13 * dec = 019 | Oct = 023 _

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.