Viewing Binary Data with hexdump
In this step, we will learn how to use the hexdump
command to view and analyze binary data in more detail.
First, let's create a binary file to work with:
dd if=/dev/urandom of=~/project/binary_file.bin bs=1024 count=1
This command generates a 1KB binary file filled with random data.
Now, let's use hexdump
to view the contents of the binary file:
hexdump -C ~/project/binary_file.bin
Example output:
00000000 b5 7f 04 3c 91 82 f7 06 dc 2b 8e 8e 5e 2e 6e 1b |...<.....+..^.n.|
00000010 7a 9a 8e 4e 3a 5e 8e 2d 9b 3e 7d 0a 0d 5d 2e 8f |z..N:^.-.:}..]..|
00000020 6d 17 a5 8a 1d 6f 9f 3d 44 f2 8e 3f 9a 8f 3a 5b |m....o.=D..?..:[|
00000030 e1 73 2f 7e 5f 8f 04 a3 1e 4a 9e 8c 8f 9a 8e 4e |.s/~_....J.....N|
The -C
option displays the output in a canonical format, showing the hexadecimal values in groups of 2 bytes and the corresponding ASCII characters on the right side.
You can also use the hexdump
command to view specific parts of the binary file. For example, to view only the first 16 bytes, you can use the -n
(number of bytes) option:
hexdump -C -n 16 ~/project/binary_file.bin
Example output:
00000000 b5 7f 04 3c 91 82 f7 06 dc 2b 8e 8e 5e 2e 6e 1b |...<.....+..^.n.|
Additionally, you can use the hexdump
command to view the file in different formats, such as the canonical format (-C
), the canonical display for single-byte character data (-c
), or the 32-bit integer format (-x
).
In the next step, we will explore how to customize the hexdump
output further to suit your specific needs.